Anda di halaman 1dari 3

#include<iostream.

h>
#include<conio.h>
void main()
{
int i, j, a[10][10],b[10][10],c[10][10],d[10][10], n, m;
char optr;
clrscr();
cout<<"\n\nEnter the number of ROWS and COLUMNS of first and second matrix:\n";
cin>>n>>m;
cout<<"\n\nEnter the elements of the first Matrix as A:\n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>a[i][j];
}
}
cout<<"\nEnter the element of the second Matrix as B:\n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>b[i][j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
c[i][j]=a[i][j]+b[i][j];
d[i][j]=a[i][j]-b[i][j];
}
}
cout<<"\nEnter the operation in the following: \n (S) for Subtraction \n (A) for Addition";
cin>>optr;
switch (optr)
{
case 'A':
cout<<"\nThe resultant Matrix C = A + B is:\n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout<<c[i][j]<<" ";
}
cout<<"\n";
break;
}
case 'S':
cout<<"\nThe resultant Matrix D = A - B is:\n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout<<d[i][j]<<" ";
}
cout<<"\n";
break;
}
}
getch();
}

Anda mungkin juga menyukai