Adding two 2x2 matrices in a c++

Hi;
I wrote the following code, But the answer does not properly!!!!
Please Help Me.


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
 #include <iostream>
#include <conio.h>
using namespace std;
void main(){
long a[2][2],b[2][2],c[2][2];
int i,j;
for(i=0;i<2;i++){
	for(j=0;j<2;j++)
	{
		cout<<"Please Enter a Number : ";
		cin>>a[2][2];
	}
}
for(i=0;i<2;i++){
   for(j=0;j<2;j++){
	   cout<<"Please Enter 2th Number : ";
       cin>>b[2][2];
	}
}	

		for(i=0;i<2;i++){
		for(j=0;j<2;j++){
	c[i][j]=a[i][j]+b[i][j];
	cout<<c[i][j]<<'\t';
	
	}
		cout<<endl;
		}
	cin.get();
	cin.get();
    }
asheykh,

change this
cin>>a[2][2];

to

cin>>a[i][j];

so that it fills the matrix correctly, instead of placing the number always into position [2][2]

I would recommend using variable names like RowCtr & ColCtr intead of i,j . It's easier to understand and will save you one day.

HTH
asheykh,

It would better to put the input from cin into it's own variable so you can check for valid input first before putting it into the array.
Topic archived. No new replies allowed.