+3 votes
in Class 12 by kratos

Write a user defined function in C++ to find the sum of both left and right diagonal elements from a two dimensional array.

1 Answer

+4 votes
by kratos
 
Best answer

void Diagsumboth(int A[][4], int n)

{

int sumLt=0,sumRt=0;

for(int i=0;i<n;i++)

{

sumLt+=A[i][i];

else

sumRt+=A[n-1-i][i];

}

cout<<”sum of left diagonal”<<sumlt<<endl;

cout<<”sum of right diagonal”<<sumRt<<endl;

}

...