Normally, we traverse a 2D Array row wise or column wise but here we need to fill array elements diagonally. How to traverse array diagonally?
How to fill 2D Array diagonally?
to move diagonal from (i,j) we have to increase i and j both
(i+1,j+1)
do it like this
for(int j=0;j<n;j++){
int x =0,y=j;
while(x<n){
// your code
x++;
y++;
}
}