You are viewing a single comment's thread. Return to all comments →
Here is the logic that I used:
{n, n-1, n-2, ..., 1, ..., n-2, n-1, n}
Those counters can be built by looping from (n-1) to (1-n), then for each value calculating abs(value) + 1.
(n-1)
(1-n)
abs(value) + 1
for (int i = n-1; i > -n; i--) { int row = abs(i) + 1; for (int j = n-1; j > -n; j--) { int col = abs(j) + 1; int cell = (row > col) ? row : col; printf("%d ", cell); } printf("\n"); }
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 →
Here is the logic that I used:
{n, n-1, n-2, ..., 1, ..., n-2, n-1, n}
.Those counters can be built by looping from
(n-1)
to(1-n)
, then for each value calculatingabs(value) + 1
.