-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcppmat.cpp
More file actions
95 lines (79 loc) · 1.41 KB
/
cppmat.cpp
File metadata and controls
95 lines (79 loc) · 1.41 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
using namespace std;
int main()
{
int n1,m1,n2,m2;
cout<<"Enter the order of the matrix 1\n";
cin>> m1>>n1;
cout<<"\n";
cout<<"Enter the order of the matrix 2\n";
cin>>m2>>n2;
if (n1 == m2)
{
int i,j,k,a[m1][n1],b[m2][n2],c[m1][n2],sum;
cout<<"Matrix Calculation\n\n";
for (i=0;i<=m1-1;i++)
{
for(j=0;j<=n1-1;j++)
{
cout<<"Enter the element of matrix 1 in row "<< i << "and column "<< j;
cin>>a[i][j];
}
}
cout<<"\n\n\n";
for (i=0;i<=m2-1;i++)
{
for(j=0;j<=n2-1;j++)
{
cout<<"Enter the element of matrix 1 in row "<< i << "and column "<< j;
cin>>b[i][j];
}
}
cout<<"The provided matrix 1 is\n";
for (i=0;i<=m1-1;i++)
{
for(j=0;j<=n1-1;j++)
{
cout<<"\t"<<a[i][j];
}
cout<<"\n";
}
cout<<"\n\n\n";
cout<<"The provided matrix 2 is\n";
for (i=0;i<=m2-1;i++)
{
for(j=0;j<=n2-1;j++)
{
cout<<"\t"<<b[i][j];
}
cout<<"\n";
}
cout<<"The product is: ";
for (k=0;k<=n2-1;k++)
{
for (i=0;i<=m1-1;i++)
{
sum = 0;
for (j=0;j<=m2-1;j++)
{
sum = sum + a[i][j]*b[j][k];
}
c[i][k] = sum;
}
}
cout<<"\n\n\n";
cout<<"The provided matrix product is\n";
for (i=0;i<=m1-1;i++)
{
for(j=0;j<=n2-1;j++)
{
cout<<"\t"<<c[i][j];
}
cout<<"\n";
}
}
else
{
cout<<"Matrix multiplication not possible";
}
}