You are viewing a single comment's thread. Return to all comments →
Most solution I see starts for loops from 0 or 1. Go out of the box and start the for loop from negative. It's easier to understand.
int main() { int n; scanf("%d", &n); for (int i = -(n-1); i < n; i++){ for (int j = -(n-1); j < n; j++){ printf("%d ", abs(j)+1 > abs(i)+1 ? abs(j)+1 : abs(i)+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 →
Most solution I see starts for loops from 0 or 1. Go out of the box and start the for loop from negative. It's easier to understand.