### Arrays.

Hi everyone! I was wondering is someone was able to assist me with this question. I'm trying to find the sum of each row and find the largest sum. This question is part of my code:

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546`` `````` srand(time(0)); int aray [5][10]; int sum=0; int average=0; int largestsum=0; cout<<"original"<=0; row--){ for(int col=9; col>=0; col--) cout<=0; row--){ for(int col=9; col>=0; col--) cout<<" "<<"\t"; cout<

I would really appreciate your help!
try this:

int tmpSum = 0;
int largeSum = 0;
int mtrx[num of rows][num of colums];
int sumArr[num of colum];

////here we run on each colum of the matrix and thus sum each row, and put the resault in a new array
for(int i = 0; i < (num of rows) ;i++ )
{
for(int j = 0; j < (num of colums); j++)
tmpSum = tmpSum + mtrx[i][j];
sumArr[i] = tmpSum;
}
///////

/////here we run on the array which has the sum of each row of the matrix and searching the largest number. (you cab also do a bouble sort to put the largest number at the end)
for(int i = 0; i < (num of colum-1); i++ )
{
if(sumArr[i] > sumArr[i+1])
largeSum = sumArr[i];
}

///example for buoble sort
int tmp = 0;
for(int i = 0;i < (num of colum -1); i++ )
{
if(sumArr[i]>sumArr[i+1]
{
sumArr[i+1] = tmp;
sumArr[i+1] = sumArr[i];
sumArr[i] = tmp;
}
}

i hope i helped you! good luck!
Thanks so much, that really helped a lot!
Topic archived. No new replies allowed.