sum of array elements

# include <iostream.h>
int main()
{
int array[7][3];
int i,j;
for (i=0;i<7;i++)
{
for (j=0;j<3;j++)
{
cin>>array[i][j];
}
cout<<endl;
}
for (i=0;i<7;i++)
{
for (j=0;j<3;j++)
{
cout<<array[i][j]<<" ";

}

cout<<endl;
}
return 0;
}



please help me to know how to get the sum of rows and the sum of rows in above matrix as a column and arow
I'm sorry i don't understand what do you want; do you want to know how to sum all the elements in that matrix?

if is it just do:
1
2
3
4
5
6
7
8
9
int sumResult = 0;
for (i=0;i<7;i++)
{
    for (j=0;j<3;j++)
   {
       sumResult += array[i][j];
   }
}
cout << sumResult << endl;

if this is not what you want to know, please try to let me understand...
no separately the sums such as below......
sum
1 2 3 6
1 2 3 6
1 2 3 6
sum 3 6 9


please reply me as possible.......


1
2
3
4
5
6
7
8
9
10
11
int row [i];

for (int i = 0; i <7; i + +)
    for (int j = 0; j <3 j + +)
          r [i] + = a [i] [j];       // sum only one row

 int b [7] [3];

for (int i = 0; i <7; i + +)
    for (int j = 0; j <3; j + +)
          b [i] [j] = a [i] [j] + a [i] [j];
Last edited on
Topic archived. No new replies allowed.