Wednesday, October 19, 2011

Program:To add two 3x3 matrices




CODE:To add two 3x3 matrix

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
clrscr();
int m[3][3] = {{1,2,4},{2,6,2},{3,5,3}}, n[3][3] = {{3,1,4},{7,2,5},{9,3,8}};
int r, c;
cout<<endl<<"Matrix M\n--------\n";
for (r=0; r<3; r++)
{
for (c=0; c<3; c++)
{
cout<<setw(3)<<m[r][c];
}
cout<<"\n";
}
cout<<"\nMatrix N\n--------\n";
for (r=0; r<3; r++)
{
for (c=0; c<3; c++)
{
cout<<setw(3)<<n[r][c];
}
cout<<"\n";
}
cout<<"\nSum of Matrices\n--------\n";
for (r=0; r<3; r++)
{
for (c=0; c<3; c++)
{
cout<<setw(3)<<m[r][c] + n[r][c];
}
cout<<"\n";
}
cout<<"\nSum of Matrices\n--------\n";
for (r=0; r<3; r++)
{
for (c=0; c<3; c++)
{
cout<<setw(3)<<m[r][c] + n[r][c];
}
cout<<"\n";
}
getch();
}
 

Article by
Chief-Editor

He is a tech Enthusiast, an Altruist and calm mentor. He loves to code. He is also a creative graphic designer. Do check out his designfolio @ Jasmeet.asia If you like This post, you can follow me on Twitter.



For Further Reading,
C++ Program

0 comments:

Post a Comment