-
Notifications
You must be signed in to change notification settings - Fork 121
/
Multiply_two_matrices.cpp
43 lines (43 loc) · 987 Bytes
/
Multiply_two_matrices.cpp
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
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter dimension of matrix: ";
cin>>n;
int elements = n*n;
int matOne[n][n], matTwo[n][n], matThree[n][n];
int i, j, k, sum=0;
cout<<"Enter "<<elements<<" Elements for first Matrix: \n";
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
cin>>matOne[i][j];
}
cout<<"\nEnter "<<elements<<" Elements for Second Matrix: \n";
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
cin>>matTwo[i][j];
}
// Multiplying two matrices...
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
sum=0;
for(k=0; k<n; k++)
sum = sum + (matOne[i][k] * matTwo[k][j]);
matThree[i][j] = sum;
}
}
cout<<"\nMultiplication Result:\n";
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
cout<<matThree[i][j]<<"\t";
cout<<endl;
}
cout<<endl;
return 0;
}