This blog consists of C and C++ programs. C and C++ programming is the basics to learn any programming language. Most of the programs are provided with their respective outputs. This blog also contains Data Structures programs using Object-Oriented Programming (C++). Some of the best books for learning C and C++ programming are also mentioned.

Monday 21 October 2013

C++ program to Add two Matrices

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3], b[3][3], c[3][3], i, j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"\nEnter the value of a["<<i+1<<"]["<<j+1<<"]...";
cin>>a[i][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"\nEnter the value of b["<<i+1<<"]["<<j+1<<"]...";
cin>>b[i][j];
}
}
cout<<"\n";
cout<<"Resultant Matrix\n\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}
getch();
}

No comments:

Post a Comment