-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path03_matrix.cpp
executable file
·47 lines (43 loc) · 925 Bytes
/
03_matrix.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
44
45
46
47
#include<iostream>
using namespace std;
void multiply(int *a, int *b, int *c, int m, int n, int z){
for(int i = 0; i < m; ++i){
for(int j = 0; j < n; ++j){
*(c+i*10+j) = 0;
for(int k = 0; k < z; ++k){
*(c+i*10+j) += *(a+i*10+k) * *(b+k*10+j);
}
}
}
}
int main(){
int a[10][10], b[10][10], c[10][10], m1, n1, m2, n2;
cout<<"Enter first matrix m, n:\n";
cin>>m1>>n1;
cout<<"Enter first matrix :\n";
for(int i = 0; i < m1; ++i){
for(int j = 0; j < n1; ++j){
cin>>a[i][j];
}
}
cout<<"Enter second matrix m, n:\n";
cin>>m2>>n2;
cout<<"Enter second matrix :\n";
for(int i = 0; i < m2; ++i){
for(int j = 0; j < n2; ++j){
cin>>b[i][j];
}
}
if(n1 == m2){
multiply(&a[0][0], &b[0][0], &c[0][0], m1, n2, n1);
for(int i = 0; i < m1; ++i){
for(int j = 0; j < n2; ++j){
cout<<c[i][j]<<" ";
}
cout<<"\n";
}
}else{
cout<<"Multiplication not possible\n";
}
return 0;
}