arrays matrix

im tryin to add a matrix array and it should look like this:

1 2 3 2 4 6 3 6 9
4 5 6 + 2 2 3 = 6 7 9
1 2 3 3 7 1 4 9 4
heres what i have done so far, i just cant get that "+" and "=" sign in there...

#include <iostream>

using namespace std;

int main()
{
int myArray[3][3] = {{1,2,3},{4,5,6},{1,2,3}};
int bArray[3][3] = {{2,4,6},{2,2,3},{3,7,1}};

for (int row = 0; row < 3; row++)
{
for(int column = 0; column < 3; column++)

{
cout << myArray[row][column] << " ";

cout << bArray[row][column] << " ";


cout << myArray[row][column] + bArray[row][column]<< " ";
}

cout << endl;
}
return 0;
}



Last edited on
First of all you are totally wrong your code will give result like this
1 2 3 2 4 6 3 6 9
4 2 6 5 2 7 6 3 9
1 3 4 2 7 9 3 1 4


not like what you mention above in your question.

This will solve your problem
for (int row = 0; row < 3; row++)
{
    for(int column = 0; column < 3; column++)
    {
        cout << myArray[row][column] << " ";
    }
    cout<<" + "; 
    for(int column = 0; column < 3; column++)
    {
        cout << bArray[row][column] << " ";
    }
    cout<<" = ";
    for(int column = 0; column < 3; column++)
    {
        cout << myArray[row][column] + bArray[row][column]<< " ";
    }
    cout << endl;
}

Topic archived. No new replies allowed.