#K78337. Snake Pattern Grid Generator
Snake Pattern Grid Generator
Snake Pattern Grid Generator
You are given a positive integer ( n ). Your task is to generate an ( n \times n ) grid filled with consecutive integers from 1 to ( n^2 ) following these rules:
- Fill the grid row by row with consecutive integers.
- For every row with an odd index (where the first row is considered index 0), reverse the order of the numbers.
For example, when ( n = 4 ), the grid should be generated as follows:
[ \begin{matrix} 1 & 2 & 3 & 4 \ 8 & 7 & 6 & 5 \ 9 & 10 & 11 & 12 \ 16 & 15 & 14 & 13 \end{matrix} ]
The output should be printed to the standard output with each row on a new line and numbers separated by a single space.
inputFormat
Input consists of a single integer ( n ) (( 1 \leq n \leq 100 )), which determines the size of the grid. The input is read from standard input.
outputFormat
Output the generated grid to standard output. Each row should be printed on a new line, with the numbers separated by a single space.## sample
1
1