Matrix

Hello, I have a matrix
1 2 3 4
5 6 7 8
9 5 9 4

and I need to add matrix rows, how I need to do that?
I need
1+5+9
2+6+5
3+7+9
4+8+4

Thanks
Last edited on
You can store a matrix in a 2D array.
1
2
3
4
5
6
7
8
9
10
int matrix[2][2]; //A 2 x 2 matrix 
for(int x = 0; x < 2; ++x) //Fill the matrix
{
    for(int y = 0; y < 2; ++y)
    {
         matrix[x][y] = 5; //Fill with number 5 in every space.
    }
}
//Elements are added like this. 
int sum = matrix[0][0] + matrix[0][1]; //Add these two elements of the matrix together.  
Topic archived. No new replies allowed.