In order to print such a pattern, you have to, well..., find a pattern.
That is, while the console pointer is at position (row, col) you should know what you have to print.
In order to find out such a pattern, it is useful to show the pattern together with the console coordinates (rows and columns)
col 0 1 2 3 4 5 6 7 8
=====================
row |
0 | 1 9 2 8 3 7 4 5 6
1 | 2 8 3 7 4 6 5
2 | 3 7 4 6 5
3 | 4 6 5
4 | 5
I see a 'conditional pattern' emerging, that is a different pattern for even and odd column numbers
- even columns (col = 0, 2, 4, ...):
p(row, col) = 1 + row + col/2;
- odd columns (col = 1, 3, 5, ...):
p(row, col) = 9 - row - col/2;
Let's verify it on two example cases
even column:
p(2,4) = 1 + 2 + 4/2 = 1 + 2 + 2 = 5
odd column:
p(1,5) = 9 - 1 - 5/2 = 9 - 1 - 2 = 6
You may check those below.
0 1 2 3 4 5 6 7 8
0 1 9 2 8 3 7 4 5 6
1 2 8 3 7 4 6 5
2 3 7 4 6 5
3 4 6 5
4 5
Now writing the corresponding
C
code is up to you.