Hi all,
I have tried to write a program which can add two matrix.
It is running well....but when I am printing out the resultant matrix it is just showing the address of the resultant elements.
For convenience, I have posted the output also.
Program:-
#include<iostream.h>
int main()
{
int mat1[3][3];
int mat2[3][3];
int i,j;
cout<<"\n1st Matrix: \n"<<flush;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>mat1[i][j];
}
}
cout<<"\n2nd Matrix: \n"<<flush;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>mat2[i][j];
}
}
int mat[3][3];
int k,l;
cout<<"\nResultant: \n"<<flush;
for(k=0;k<3;k++)
{
for(l=0;l<3;l++)
{
mat[k][l]=(mat1[k][l]+mat2[k][l]);
cout<<" "<<mat[l]<<flush;
}
cout<<"\n"<<flush;
}
return 0;
}
O/p:
1st Matrix:
1 1 1
1 1 1
1 1 1
2nd Matrix:
1 1 1
1 1 1
1 1 1
Resultant:
0xbfe1b810 0xbfe1b81c 0xbfe1b828
0xbfe1b810 0xbfe1b81c 0xbfe1b828
0xbfe1b810 0xbfe1b81c 0xbfe1b828