Given a two dimensional array of integers A write a method

Given a two dimensional array of integers A[] [], write a method that returns the row whose summation of elements is the largest. e.g. Given array 1, 2, 0, 10 2, 0, 4, 4 0, 2, 5, 11 The sum of each row is as follows; 13 for row 0, 10 for row 1, 18 for row 2. Therefore, the returned row will be 0, 2, 5, 11

Solution

int largerrow(int A [3][4])

{

int i,j;

int sum[3]={0,0,0},k=0;

for (i=0;i <=2;i++){

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

sum[k]= A [i][j]+sum[k];

}

k++;

}

if (sum [0]>sum [1])

{

if(sum [0]>sum [2])

return A [0][4];

else

return A [2][4];

}

else if (sum [1]>sum [2])

return A[1][4];

else

return A [2][4];

}

 Given a two dimensional array of integers A[] [], write a method that returns the row whose summation of elements is the largest. e.g. Given array 1, 2, 0, 10

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site