You are viewing a single comment's thread. Return to all comments →
I have a solution which is way faster and more simple than using the array
int main() {
int n; scanf("%d", &n); // Complete the code to print the pattern. for (int i = 1; i <= 2 * n - 1; i++) { int d = abs(i - n); for(int j = 1; j <= n - 1 - d; j++) printf("%d ", n - j + 1); for(int j = 1; j <= 2 * d + 1; j++) printf("%d ", d + 1); for(int j = n - 1 - d; j >= 1; j--) printf("%d ", n - j + 1); 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 →
I have a solution which is way faster and more simple than using the array
include
include
include
include
int main() {
}