AD1

Friday 11 May 2018

The diagonal parallel to the main

Statement

Given an integer n, produce a two-dimensional array of size and complete it according to the following rules, and print with a single space between characters:
  • On the main diagonal write .
  • On the diagonals adjacent to the main, write .
  • On the next adjacent diagonals write and so forth.
Print the elements of the resulting array.
sample 
n=7
0 1 2 3 4 5 6
1 0 1 2 3 4 5
2 1 0 1 2 3 4
3 2 1 0 1 2 3
4 3 2 1 0 1 2
5 4 3 2 1 0 1
6 5 4 3 2 1 0

No comments:

Post a Comment