Pages

Saturday 19 March 2011

PROGRAM TO SUBTRACT TWO MATRIX

DESCRIPTION- This program takes two matrices as input and then generate the output matrix after subtracting the two input matrices.The order of input matrix must be same.
FOR EXAMPLE-: If we have two input  matrices as---------

             2   3   1                                 2   2   1
             1   5   7                                 1   4   6
             2   8   1                                 1   3   1

Then program generate output as---------
                                  0   1   0
                                  0   1   1
                                  1   5   0

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<<"subtraction 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.