#include<iostream.h>
#include<conio.h>
main()
{
int a[10][10],b[10][10],row,col,num,c[10][10],m,n,p,q,i,j,k;
cout<<"\n\t\t\t***********************";
cout<<"\n\t\t\t* PROGRAM OF MATRICES *";
cout<<"\n\t\t\t***********************";
cout<<"\n\n\n\n\t\tMade By:";
cout<<"\tzeeshan";
cout<<"\n\n\n\n\n\n\n\t\t\t\t\tPress any key to continue....!!";
getch();
do{
system("cls");
cout<<"\t\t\t"<<(char)2<<" MAIN MENU "<<(char)2<<endl<<endl;
cout<<"\t\t1.Addition of matrix"<<endl;
cout<<"\t\t2.Substraction of matrix"<<endl;
cout<<"\t\t3.Transpose of a matrix"<<endl;
cout<<"\t\t4.Multiplication of matrices\n"<<endl;
cout<<"\t\t5.Exit program\n\n";
cout<<"\n enter your choice :\n";
cin>>num;
switch(num)
{
case 1:
{
system("cls");
cout<<" enter number of rows :"<<endl;
cin>>row;
cout<<" enter number of columns :"<<endl;
cin>>col;
cout<<" enter values of first matrix :"<<endl;
for(i=0;i<col;i++) //to enter values of first matrix
{
for(j=0;j<row;j++)
{
cin>>a[i][j];
}
cout<<endl;
}
cout<<" enter values of 2nd matrix :"<<endl;
for(i=0;i<col;i++) //to enter values of 2nd matrix
{
for(j=0;j<row;j++)
{
cin>>b[i][j];
}
cout<<endl;
}
system("cls");
cout<<"\nfirst matrix:\n";
for(i=0;i<row;++i)
{for(j=0;j<col;++j)
{cout<<a[i][j]<<" ";}
cout<<endl;}
cout<<"\nsecond matrix:\n";
for(i=0;i<row;++i)
{for(j=0;j<col;++j)
{cout<<b[i][j]<<" ";}
cout<<endl;}
cout<<"the additon of your matices is :\n"<<endl;
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
a[i][j]=a[i][j]+b[i][j];
cout<<a[i][j]<<" ";
}
cout<<endl<<endl;
}
getch();
break;
}
case 2:
{
system("cls");
cout<<" enter number of rows :"<<endl;
cin>>row;
cout<<" enter number of columns :"<<endl;
cin>>col;
cout<<" enter values of first matrix :"<<endl;
for(i=0;i<col;i++) //to enter values of first matrix
{
for(j=0;j<row;j++)
{
cin>>a[i][j];
}
cout<<endl;
}
cout<<" enter values of 2nd matrix :"<<endl;
for(i=0;i<col;i++) //to enter values of 2nd matrix
{
for(j=0;j<row;j++)
{
cin>>b[i][j];
}
cout<<endl;
}
system("cls");
cout<<"\nfirst matrix:\n";
for(i=0;i<row;++i)
{for(j=0;j<col;++j)
{cout<<a[i][i]<<" ";}
cout<<endl;}
cout<<"\nsecond matrix:\n";
for(i=0;i<row;++i)
{for(j=0;j<col;++j)
{cout<<b[i][j]<<" ";}
cout<<endl;}
cout<<"the substraction of your matices is :\n"<<endl;
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
a[i][j]=a[i][j]-b[i][j];
cout<<a[i][j]<<" ";
}
cout<<endl<<endl;
}
getch();
break;
}
case 3:
{
system("cls");
cout<<" enter number of rows :"<<endl;
cin>>row;
cout<<" enter number of columns :"<<endl;
cin>>col;
cout<<" enter values of matrix :"<<endl;
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
cin>>a[i][j];
}
cout<<endl;
}
system("cls");
cout<<"\n your matrix :\n"<<endl;
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
cout<<a[i][j];
cout<<" ";
}
cout<<endl<<endl;
}
cout<<"\n the transpose of your matrix :\n"<<endl;
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
cout<<a[j][i];
cout<<" ";
}
cout<<endl<<endl;
}
getch();
break;
}
case 4:
{
system("cls");
cout<<(char)2<<" You can multiply two matrices if, and only if,\n";
cout<<" the number of columns in the first matrix equals\n";
cout<<"\n the number of rows in the second matrix. "<<endl<<endl;
cout<<"Enter rows and columns of first matrix:";
cin>>m>>n;
cout<<"Enter rows and columns of second matrix:";
cin>>p>>q;
if(n==p)
{
cout<<"\nEnter first matrix:\n";
for(i=0;i<m;++i)
for(j=0;j<n;++j)
cin>>a[i][j];
cout<<"\nEnter second matrix:\n";
for(i=0;i<p;++i)
for(j=0;j<q;++j)
cin>>b[i][j];
system("cls");
cout<<"\nfirst matrix:\n";
for(i=0;i<m;++i)
{for(j=0;j<n;++j)
{cout<<a[i][i]<<" ";}
cout<<endl;}
cout<<"\nsecond matrix:\n";
for(i=0;i<p;++i)
{for(j=0;j<q;++j)
{cout<<b[i][j]<<" ";}
cout<<endl;}
cout<<"\nThe new matrix is:\n";
for(i=0;i<m;++i)
{
for(j=0;j<q;++j)
{
c[i][j]=0;
for(k=0;k<p;++k)
{ c[i][j]=c[i][j]+(a[i][k]*b[k][j]);}
cout<<c[i][j]<<" ";
}
cout<<"\n";
}
}
else
cout<<"\nSorry!!!! Matrix multiplication can't be done";
getch();
break;
}
case 5:
{
cout<<"\n\n\t\t\t\t\t\tbye...!!!";
}
}
}while(num!=5);
getch();
}
#include<conio.h>
main()
{
int a[10][10],b[10][10],row,col,num,c[10][10],m,n,p,q,i,j,k;
cout<<"\n\t\t\t***********************";
cout<<"\n\t\t\t* PROGRAM OF MATRICES *";
cout<<"\n\t\t\t***********************";
cout<<"\n\n\n\n\t\tMade By:";
cout<<"\tzeeshan";
cout<<"\n\n\n\n\n\n\n\t\t\t\t\tPress any key to continue....!!";
getch();
do{
system("cls");
cout<<"\t\t\t"<<(char)2<<" MAIN MENU "<<(char)2<<endl<<endl;
cout<<"\t\t1.Addition of matrix"<<endl;
cout<<"\t\t2.Substraction of matrix"<<endl;
cout<<"\t\t3.Transpose of a matrix"<<endl;
cout<<"\t\t4.Multiplication of matrices\n"<<endl;
cout<<"\t\t5.Exit program\n\n";
cout<<"\n enter your choice :\n";
cin>>num;
switch(num)
{
case 1:
{
system("cls");
cout<<" enter number of rows :"<<endl;
cin>>row;
cout<<" enter number of columns :"<<endl;
cin>>col;
cout<<" enter values of first matrix :"<<endl;
for(i=0;i<col;i++) //to enter values of first matrix
{
for(j=0;j<row;j++)
{
cin>>a[i][j];
}
cout<<endl;
}
cout<<" enter values of 2nd matrix :"<<endl;
for(i=0;i<col;i++) //to enter values of 2nd matrix
{
for(j=0;j<row;j++)
{
cin>>b[i][j];
}
cout<<endl;
}
system("cls");
cout<<"\nfirst matrix:\n";
for(i=0;i<row;++i)
{for(j=0;j<col;++j)
{cout<<a[i][j]<<" ";}
cout<<endl;}
cout<<"\nsecond matrix:\n";
for(i=0;i<row;++i)
{for(j=0;j<col;++j)
{cout<<b[i][j]<<" ";}
cout<<endl;}
cout<<"the additon of your matices is :\n"<<endl;
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
a[i][j]=a[i][j]+b[i][j];
cout<<a[i][j]<<" ";
}
cout<<endl<<endl;
}
getch();
break;
}
case 2:
{
system("cls");
cout<<" enter number of rows :"<<endl;
cin>>row;
cout<<" enter number of columns :"<<endl;
cin>>col;
cout<<" enter values of first matrix :"<<endl;
for(i=0;i<col;i++) //to enter values of first matrix
{
for(j=0;j<row;j++)
{
cin>>a[i][j];
}
cout<<endl;
}
cout<<" enter values of 2nd matrix :"<<endl;
for(i=0;i<col;i++) //to enter values of 2nd matrix
{
for(j=0;j<row;j++)
{
cin>>b[i][j];
}
cout<<endl;
}
system("cls");
cout<<"\nfirst matrix:\n";
for(i=0;i<row;++i)
{for(j=0;j<col;++j)
{cout<<a[i][i]<<" ";}
cout<<endl;}
cout<<"\nsecond matrix:\n";
for(i=0;i<row;++i)
{for(j=0;j<col;++j)
{cout<<b[i][j]<<" ";}
cout<<endl;}
cout<<"the substraction of your matices is :\n"<<endl;
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
a[i][j]=a[i][j]-b[i][j];
cout<<a[i][j]<<" ";
}
cout<<endl<<endl;
}
getch();
break;
}
case 3:
{
system("cls");
cout<<" enter number of rows :"<<endl;
cin>>row;
cout<<" enter number of columns :"<<endl;
cin>>col;
cout<<" enter values of matrix :"<<endl;
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
cin>>a[i][j];
}
cout<<endl;
}
system("cls");
cout<<"\n your matrix :\n"<<endl;
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
cout<<a[i][j];
cout<<" ";
}
cout<<endl<<endl;
}
cout<<"\n the transpose of your matrix :\n"<<endl;
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
cout<<a[j][i];
cout<<" ";
}
cout<<endl<<endl;
}
getch();
break;
}
case 4:
{
system("cls");
cout<<(char)2<<" You can multiply two matrices if, and only if,\n";
cout<<" the number of columns in the first matrix equals\n";
cout<<"\n the number of rows in the second matrix. "<<endl<<endl;
cout<<"Enter rows and columns of first matrix:";
cin>>m>>n;
cout<<"Enter rows and columns of second matrix:";
cin>>p>>q;
if(n==p)
{
cout<<"\nEnter first matrix:\n";
for(i=0;i<m;++i)
for(j=0;j<n;++j)
cin>>a[i][j];
cout<<"\nEnter second matrix:\n";
for(i=0;i<p;++i)
for(j=0;j<q;++j)
cin>>b[i][j];
system("cls");
cout<<"\nfirst matrix:\n";
for(i=0;i<m;++i)
{for(j=0;j<n;++j)
{cout<<a[i][i]<<" ";}
cout<<endl;}
cout<<"\nsecond matrix:\n";
for(i=0;i<p;++i)
{for(j=0;j<q;++j)
{cout<<b[i][j]<<" ";}
cout<<endl;}
cout<<"\nThe new matrix is:\n";
for(i=0;i<m;++i)
{
for(j=0;j<q;++j)
{
c[i][j]=0;
for(k=0;k<p;++k)
{ c[i][j]=c[i][j]+(a[i][k]*b[k][j]);}
cout<<c[i][j]<<" ";
}
cout<<"\n";
}
}
else
cout<<"\nSorry!!!! Matrix multiplication can't be done";
getch();
break;
}
case 5:
{
cout<<"\n\n\t\t\t\t\t\tbye...!!!";
}
}
}while(num!=5);
getch();
}