MENU
Question -

Write a function in C++ to print the sum of all the non-negative elements present on both the diagonal of a two dimensional array passed as the argument to the function.



Answer -

void Diagonal (int A[] [20] , int N)
 {
 int K, Sdiag=0;
 for(int K=0;K 0)
 Sdiag+=A [K] [K] ;
 for(int K= 0;K 0 )
 Sdiag+=A[N-K-1] [K] ;
 cout<<"Sum of all the non-negative elements on both the diagonals= "<
 }

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
×