Summing two Matrices

Hey, I am very new at C++ and I am trying to figure out what the problem is with my code. I am just trying to get it to add two Matrices.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

// add Matrices 
#include<iostream>
using namespace std;

int c[2][3];
int i,j;
int main() {
	int aMatrix [2] [3] = 
	{
		{-5,2,8},
		{1,0,0}
	};

	cout << aMatrix<< endl;

	int bMatrix [2] [3] =
	{
		{1,0,2},
		{0,3,-6}
	};

	cout << bMatrix<< endl;

	for (i=0; i<2; i++){
		for (j=0; j<3; j++){
			 c[i][j]=aMatrix[i][j]+bMatrix[i][j];
			 cout << c[i][j];
		}
	}
	
	int dumbyload;
	cin >>dumbyload;
}


the output is this
0060FB3C
0060FB1C
-421013-6
cout << aMatrix<< endl;

This is just going to print out the memory address of the first element of the array, not the entire array. That's why you see something like 0060FB3C in the first two outputs.


The addition looks like it worked, but there's no spacing between the resulting values so they're all clumped together here -421013-6
Last edited on
Thank you, What is the correct way to get it to print out the matrix values as apposed to the address? and what is the proper way to get it to space out like a matrix?
Last edited on
Topic archived. No new replies allowed.