Pages

Saturday 19 March 2011

PROGRAM TO ADD TWO MATRIX

DESCRIPTION-:This program takes two matrices as input and then generate the output matrix which contain the addition of two input matrices.The order of two input matrices must be same.
FOR EXAMPLE-:  If we have two input matrices as-------
               2   6   1                           2   1   5
               3   1   3                           7   2   1
               1   0   5                           1   7   0


Then program generate output as-------
                                     4   7   6

                                    10  3   4
                                     2   7   5

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n,a[10][10],b[10][10],c[10][10];
cout<<"enter the order of matrix A";
cin>>n;
cout<<"enter value of elements of matrix A"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"enter the order of matrix B";
cin>>n;
cout<<"enter values of elements of matrix B"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>b[i][j];
}
}
cout<<"values of elements of matrix A are"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<a[i][j];
}
cout<<"\n";
}
cout<<"values of elements of matrix B are"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<b[i][j];
}
cout<<"\n";
}
cout<<"addition of matrix A and B is"<<"\n";
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}
getch();
}

0 comments:

Post a Comment

 
Copyright (c) 2010 Concepts Of C++. Design by WPThemes Expert

Blogger Templates and RegistryBooster.