-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMAT_MULT.CPP
More file actions
43 lines (39 loc) · 923 Bytes
/
MAT_MULT.CPP
File metadata and controls
43 lines (39 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//Multiplication of two matrices
#include<iostream.h>
#include<conio.h>
void main()
{int m,n,p,q,a[10][10],b[10][10],c[10][10]={0};
clrscr();
cout<<"Enter the dimension of the first matrix "<<endl;
cin>>m>>n;
cout<<"Enter the dimension of the second matrix "<<endl;
cin>>p>>q;
int i,j;
if(m==p&&n==q)
{
cout<<"Enter the elements of the first matrix "<<endl;
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"Enter the elements of the second matrix "<<endl;
for(i=0;i<p;i++)
{ for(j=0;j<q;j++)
cin>>b[i][j];
}
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
{ for(int k=0;k<n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
cout<<"The multiplication of the two matrices is "<<endl;
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
cout<<c[i][j]<<"\t";
}
}
else
cout<<"The matrices are not multiplicable ";
getch();
}