-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatrixMultiplication.cpp
67 lines (48 loc) · 1.53 KB
/
MatrixMultiplication.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include <string.h>
using namespace std;
int main()
{
int arr1[300][300],arr2[300][300],multiply[300][300],sum, m1, n1, m2, n2, i, j,k,*p[300],*q[300],*r[300];
cout << endl <<"Enter the row dimension of the matrix: "<<endl;
cin>>m1;
cout<< endl << "Enter the column dimension of the matrix: "<< endl;
cin>>n1;
cout<<endl<<"Enter the element for first matrix: \n"<<endl;
for(int i=0;i<m1;i++){
for(int j=0;j<n1;j++){
cin>>arr1[i][j];
}
}
cout<<endl<<"Enter the row dimension of the matrix: "<<endl;
cin>>m2;
cout<<endl<<"Enter the column dimension of the matrix: "<<endl;
cin>>n2;
if(n1!=m2){
cout<<endl<<"dimension error\n"<<endl;
return 0;
}
cout<<endl<<"Enter the element for second matrix: \n"<<endl;
for(int i=0;i<m2;i++){
for(int j=0;j<n2;j++){
cin>>arr2[i][j];
}
}
//for(int i=0;i<m1;i++) p[i]=&arr1[i][j];
//for(int i=0;i<m1;i++) q[i]=&arr2[i][j];
//for(int i=0;i<m1;i++) r[i]=&matrix[i][j];
for(int i=0;i<m1;i++){
multiply[i][j]=0;
for(int j=0;j<n2;j++){
//*(*(r+i)+sum) = 0;
multiply[i][j]= multiply[i][j]+ arr1[i][k]*arr2[k][j];
//cout<<endl<<"\t"<<*(*(r+i)+j))endl;
}
}
for(int i=0;i<m1;i++){
for(int j=0;j<n2;j++){
cout<<endl<<"\t"<<multiply[i][j]<<endl;
}
cout<<endl<<"\n"<<endl;
}
}