1.

Write a user-defined function AddEnd4(int A[][4],int R,int C) in C++ to find and display the sum of all the values, which are ending with 4 (i.e., unit place is 4). For example if the content of array is:2416141954The output should be 42

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;

}



Discussion

No Comment Found

Related InterviewSolutions