+ 1
To find the sum of both diagonal elements
write a program in c++
3 Réponses
+ 9
#define N 3
int arr[N][N];
int sum1=0,sum2=0;
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
if(i==j)
sum1+=arr[i][j];
if((i+j)==N-1)
sum2+=arr[i][j];
}
}
cout<<sum1;
cout<<sum2;
+ 9
Sorry for all the typos I'm busy doing something else. lol But basically you add both diagonals that way.
+ 5
use arrays to hold data,and then andd them