### All Operations in Matrix Programs :-

• Matrix Subtraction
• Matrix Multiplication

[cpp]
#include<iostream.h>
void sub();
void mul();
void main()
{
int ch,i,j;
cout<<"*********************************************************\n";
do
{
cout<<"Press 1 for matrix addition\nPress 2 for matrix substration\
nPress 3 for matrix multiplication\nPress4 for matrix transpose\n
Press 5 for exit\n";
cin>>ch;
switch (ch)
{
case 1:
for(i=0; i<=2; i++)
{
cout<<"Enter the element for "<<i+1<<" row : \n";
for(j=0; j<=2; j++)
{
cout<<"Enter the element for "<<j+1<<" column : ";
cin>>a[i][j];
}
cout<<"\n";
}

for(i=0; i<=2; i++)
{
cout<<"Enter the element for "<<i+1<<" row : \n";
for(j=0; j<=2; j++)
{
cout<<"Enter the element for "<<j+1<<" column : ";
cin>>b[i][j];
}
cout<<"\n";
}
cout<<"The array after addition is : \n";
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
}
cout<<"\n";
}
break;

case 2:
for(i=0; i<=2; i++)
{
cout<<"Enter the element for "<<i+1<<" row : \n";
for(j=0; j<=2; j++)
{
cout<<"Enter the element for "<<j+1<<" column : ";
cin>>a[i][j];
}
cout<<"\n";
}

for(i=0; i<=2; i++)
{
cout<<"Enter the element for "<<i+1<<" row : \n";
for(j=0; j<=2; j++)
{
cout<<"Enter the element for "<<j+1<<" column : ";
cin>>b[i][j];
}
cout<<"\n";
}
sub();
cout<<"The array after addition is : \n";
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
}
cout<<"\n";
}
break;

case 3:
for(i=0; i<=2; i++)
{
cout<<"Enter the element for "<<i+1<<" row : \n";
for(j=0; j<=2; j++)
{
cout<<"Enter the element for "<<j+1<<" column : ";
cin>>a[i][j];
}
cout<<"\n";
}

for(i=0; i<=2; i++)
{
cout<<"Enter the element for "<<i+1<<" row : \n";
for(j=0; j<=2; j++)
{
cout<<"Enter the element for "<<j+1<<" column : ";
cin>>b[i][j];
}
cout<<"\n";
}
mul();
cout<<"The array after addition is : \n";
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
}
cout<<"\n";
}
break;

case 4:
for(i=0; i<=2; i++)
{
cout<<"Enter the element for "<<i+1<<" row : \n";
for(j=0; j<=2; j++)
{
cout<<"Enter the element for "<<j+1<<" column : ";
cin>>a[i][j];
}
cout<<"\n";
}
cout<<"The array is : \n";
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
cout<<a[j][i]<<"\t";
}
cout<<"\n";
}
break;

}
}
while(ch!=5);
cout<<"*********************************************************\n";
}

{
int i,j;
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
}
}
}

void sub()
{
int i,j;
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
}
}
}

void mul()
{
int i,j;
int m;
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
m=0;
for(int n=0; n<=2; n++)
{
m+=a[i][n]*b[n][j];
}