C++ Program To Substract Two Matrix
//C++ Program To Substract Two Matrix
#include<iostream>
using namespace std;
int main()
{
int a[20][20],b[20][20],m,n,p,q,i,j;
cout<<"Enter The No. Of Rows Of Matrix A:--";
cin>>m;
cout<<"Enter The No. Of Column Of Matrix A:--";
cin>>n;
cout<<"Enter The No. Of Rows Of Matrix B:--";
cin>>p;
cout<<"Enter The No. Of Column Of Matrix B:--";
cin>>q;
if(m!=p&&n!=q)
cout<<"Matrices Are Not Compareable !!!";
else
{
//Entering The Element Of Matrix A
cout<<"\nEnter The Elements Of Matrix A:--\n";
for(i=0;i<m;i++)
{
cout<<"\nEnter The Element Of "<<i+1<<" Row--\n";
for(j=0;j<n;j++)
{
cout<<"Enter The Element Of "<<j+1<<" Column:--";
cin>>a[i][j];
}
}
//Entering The Elements Of Matrix B
cout<<"\nEnter The Elements Of Matrix B:--\n";
for(i=0;i<m;i++)
{
cout<<"\nEnter The Element Of "<<i+1<<" Row--\n";
for(j=0;j<n;j++)
{
cout<<"Enter The Element Of "<<j+1<<" Column:--";
cin>>b[i][j];
}
}
cout<<"\nMatrix A:--";
for(i=0;i<m;i++)
{
cout<<"\n\t";
for(j=0;j<n;j++)
{
cout<<a[i][j]<<" ";
}
}
cout<<"\nMatrix B:--";
for(i=0;i<m;i++)
{
cout<<"\n\t";
for(j=0;j<n;j++)
{
cout<<b[i][j]<<" ";
}
}
cout<<"\nDifference Of Matrix A & B:--";
for(i=0;i<m;i++)
{
cout<<"\n\t";
for(j=0;j<n;j++)
{
cout<<a[i][j]-b[i][j]<<" ";
}
}
}
return 0;
}
//C++ Program To Substract Two Matrix
#include<iostream>
using namespace std;
int main()
{
int a[20][20],b[20][20],m,n,p,q,i,j;
cout<<"Enter The No. Of Rows Of Matrix A:--";
cin>>m;
cout<<"Enter The No. Of Column Of Matrix A:--";
cin>>n;
cout<<"Enter The No. Of Rows Of Matrix B:--";
cin>>p;
cout<<"Enter The No. Of Column Of Matrix B:--";
cin>>q;
if(m!=p&&n!=q)
cout<<"Matrices Are Not Compareable !!!";
else
{
//Entering The Element Of Matrix A
cout<<"\nEnter The Elements Of Matrix A:--\n";
for(i=0;i<m;i++)
{
cout<<"\nEnter The Element Of "<<i+1<<" Row--\n";
for(j=0;j<n;j++)
{
cout<<"Enter The Element Of "<<j+1<<" Column:--";
cin>>a[i][j];
}
}
//Entering The Elements Of Matrix B
cout<<"\nEnter The Elements Of Matrix B:--\n";
for(i=0;i<m;i++)
{
cout<<"\nEnter The Element Of "<<i+1<<" Row--\n";
for(j=0;j<n;j++)
{
cout<<"Enter The Element Of "<<j+1<<" Column:--";
cin>>b[i][j];
}
}
cout<<"\nMatrix A:--";
for(i=0;i<m;i++)
{
cout<<"\n\t";
for(j=0;j<n;j++)
{
cout<<a[i][j]<<" ";
}
}
cout<<"\nMatrix B:--";
for(i=0;i<m;i++)
{
cout<<"\n\t";
for(j=0;j<n;j++)
{
cout<<b[i][j]<<" ";
}
}
cout<<"\nDifference Of Matrix A & B:--";
for(i=0;i<m;i++)
{
cout<<"\n\t";
for(j=0;j<n;j++)
{
cout<<a[i][j]-b[i][j]<<" ";
}
}
}
return 0;
}
0 Comments