0

A(n×n) array.Program to find sum of all elements which lie on either diagonal.

4th Mar 2017, 2:30 PM
Shah faisal khan
Shah faisal khan - avatar
2 Respostas
+ 3
something better for(I=0;I<size;I++) sum+=ar[I][I]+ar[I][size-i-1]; if(size%2!=0) sum-=ar[size/2][size/2];
4th Mar 2017, 3:29 PM
Megatron
Megatron - avatar
0
1 take two loops i & j 2 if i == j 3 then sum = sum + array[i][j]
4th Mar 2017, 3:11 PM
Mohd Shahid Ameen
Mohd Shahid Ameen - avatar