C++ Programs - Matrix multiplication, transpose and addition

C++ Program for matrix multiplication, transpose and addition

#include<iostream>
using namespace std;
int a[10][10],b[10][10],add[10][10],mul[10][10],tran[10][10];
int sum=0,k,i,j,r,c,r1,c1,x;
int ad(int (&p)[10][10],int (&q)[10][10]){
if(r==r1&&c==c1)
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
add[i][j]=(a[i][j])+(b[i][j]);
}
}
}
else
cout<<"for matrix addition rows and column should be equal"<<endl;
}
int m(int (&p)[10][10],int (&q)[10][10]){
if(r==c1)
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
for(k=0;k<r;k++)
{
sum=sum+((a[i][k])*(b[j][k]));
}
mul[i][j]=sum;
sum=0;
}
}
}
else
cout<<"matrix multiplication is not possible"<<endl;
}
int tra(int (&p)[10][10],int (&q)[10][10]){


for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
tran[i][j]=a[j][i];
}
}
}


int main(){

cout<<"enter the number of rows in 1st matrix "<<endl;
cin>>r;
cout<<"enter the number of columns in 1st matrix"<<endl;
cin>>c;
cout<<"enter the number of rows in 2nd matrix "<<endl;
cin>>r1;
cout<<"enter the number of columns in 2nd matrix"<<endl;
cin>>c1;
cout<<"enter the number of of first matrix"<<endl;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
cout<<"enter the values of second matrix"<<endl;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cin>>b[i][j];
}
}
cout<<" first matrix"<<endl;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<a[i][j];
}
cout<<"\n";
}
cout<<" second matrix"<<endl;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<b[i][j];
}
cout<<"\n";
}

while(1)
{
cout<<"select one of the following operations:\n1)addition\n2)multiplication\n3)transpose\n"<<endl;
cin>>x;
switch(x){
case 1:
ad(a,b);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<add[i][j];
}
cout<<"\n";
}

break;
case 2:
m(a,b);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<mul[i][j];
}
cout<<"\n";
}

break;
case 3:
tra(a,b);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<tran[i][j];
}
cout<<"\n";
}

break;
default:
cout<<"invalid entry\n";
break;
}
}
}