-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiplication.cpp
More file actions
66 lines (55 loc) · 1.36 KB
/
multiplication.cpp
File metadata and controls
66 lines (55 loc) · 1.36 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;
int main()
{
cout << "Enter the row and column of first matrix : ";
int row1, col1;
cin >> row1 >> col1;
cout << "Enter the row and colums of second matrix : ";
int row2, col2;
cin >> row2 >> col2;
int mat1[row1][col1];
int mat2[row2][col2];
cout << "Enter the first matrix : \n";
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col1; j++)
{
cin >> mat1[i][j];
}
}
cout << "Enter the second matrix : \n";
for (int i = 0; i < row2; i++)
{
for (int j = 0; j < col2; j++)
{
cin >> mat2[i][j];
}
}
if (col1 == row2)
{
int matrix[row1][col2];
memset(matrix, 0, sizeof(matrix));
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col2; j++)
{
for (int k = 0; k < row2; k++)
{
matrix[i][j] += (mat1[i][k] * mat2[k][j]);
}
}
}
for(int i = 0; i < row1; i++)
{
for(int j = 0; j < col2; j++)
{
cout << matrix[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
else cout << "Multiplication isn't possible!" << endl;
return 0;
}