You are viewing a single comment's thread. Return to all comments →
int main() { int n; scanf("%d", &n); for(int i = -n + 1;i <= 0;i++){ for(int j = 0;j < i + n - 1;j++){ printf("%d ", n - j); } for(int j = n + i;j <= n - i;j++){ printf("%d ", -i + 1); } for(int j = i + n - 2;j >= 0;j--){ printf("%d ", n - j); } printf("\n"); } for(int i = 1;i < n;i++){ for(int j = 0;j <= n - 1 - i;j++){ printf("%d ", n - j); } for(int j = n - i;j < n + i;j++){ printf("%d ", i + 1); } for(int j = n - 1 - i - 1;j >= 0;j--){ printf("%d ", n - j); } printf("\n"); } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Printing Pattern Using Loops
You are viewing a single comment's thread. Return to all comments →
include
int main() { int n; scanf("%d", &n); for(int i = -n + 1;i <= 0;i++){ for(int j = 0;j < i + n - 1;j++){ printf("%d ", n - j); } for(int j = n + i;j <= n - i;j++){ printf("%d ", -i + 1); } for(int j = i + n - 2;j >= 0;j--){ printf("%d ", n - j); } printf("\n"); } for(int i = 1;i < n;i++){ for(int j = 0;j <= n - 1 - i;j++){ printf("%d ", n - j); } for(int j = n - i;j < n + i;j++){ printf("%d ", i + 1); } for(int j = n - 1 - i - 1;j >= 0;j--){ printf("%d ", n - j); } printf("\n"); } return 0; }