Multiplication of Arrays


Program for Multiplication of Multidimensional arrays



#include<iostream>
#include<conio.h> 

int main()


{


int a[5][5],b[5][5],c[5][5];
int i,j,k,m,n,p,q;

cout
<<"Enter the size of first Array"<<endl;

cin>>m
gt;>n;

cout
<<"Enter the size of Second Array"<<endl;

cin
gt;>pgt;>q;

if(n==p)


{


cout<<"Enter the First Array"<<endl;

for(i=0;i<m;i++)


{


for(j=0;j<n;j++)
{    

cin
gt;>c[i][j];

}


}


cout
<<"Enter the second Array"<<endl;

for (i=0;i<p;i++)


{


for(j=0;j<q;j++)


cin
gt;>c[i][j];

}


cout
<<" Product of two Arrays"<<endl;

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];


}


for(i=0;i<m;i++)


{


for(j=0;j<q;j++)
{    

cout
<<c[i][j]<<" ";

}


cout
<<endl;

}

}

else

cout<<"Not possible";

getch();

return 0;

}


No comments :

Post a Comment