Computer Science, asked by TbiaSamishta, 1 year ago

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

Answers

Answered by Brainlycurator
0

void addition ()

{int arr [ ], size, i, j, sum1 =0,

sum2=0, tot-sum=0;

count <<"Enter the sixe of the 2D arrary:";

in>> size;

for(i=0; i< size; i++)

{for (jj=0; j<size;j++)

{count << "Enter element:";in>> ar [i] [j];} }

for (i=0; i<size; i++)

{for(jj=0: j<size; j++)

{if (i==j)sum1= sum1 + arr [i] [j];}}

for (i=0; i<size; i++)

{for(j=0; j<size; j++)

{if ( (i+j) == (size-1) )

sum2=sum2 + arr[i] [j];}}

tot-sum = sum1 + sum2;

count <<" The total sum of the  left and right

diagonal element is: " >> tot - sum;}

Similar questions