-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix Multiplication.cpp
More file actions
100 lines (97 loc) · 1.71 KB
/
Copy pathMatrix Multiplication.cpp
File metadata and controls
100 lines (97 loc) · 1.71 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
96
97
98
99
100
#include<iostream.h>
#include<conio.h>
class matrix
{
float a[10][10],b[10][10],c[10][10],r1,c1,r2,c2;
public:
int i,j,k;
void input();
void mult_matrix();
void output();
};
void matrix:: input()
{
// aa:
{
cout<<"\n Enter Number Rows and Columns of First Matrix:";
cin>>r1>>c1;
cout<<"\n Enter Number Rows and Columns of Second Matrix:";
cin>>r2>>c2;
while(c1!=r2)
{
cout<<"ERROR!! \n COLUMN OF FIRST MATRIX IS NOT EQUAL TO ROW OF SECOND MATRIX \n";
getch();
// goto aa;
cout<<"\n Enter Number Rows and Columns of First Matrix:";
cin>>c1;
cout<<"\n Enter Number Rows and Columns of Second Matrix:";
cin>>r2;
}
cout<<"\n Enter element of Matrix 1: \n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<"\n Enter element a"<<i+1<<j+1<<":";
cin>>a[i][j];
}
}
cout<<"\n Enter element of Matrix 2:\n ";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
cout<<"\n Enter element b"<<i+1<<j+1<<":";
cin>>b[i][j];
}
}
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
c[i][j]=0;
}
void matrix::mult_matrix()
{
for( i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
for( k=0;k<c1;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
}
}
}
void matrix::output()
{
cout<<"\n First Matrix: \n";
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
cout<<" "<<a[i][j]<<"\t";
cout<<endl;
}
cout<<"\n Second Matrix: \n";
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
cout<<" "<<b[i][j]<<"\t";
cout<<endl;
}
cout<<"\n \n Resultant Matrix:\n \n";
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
cout<<" "<<c[i][j]<<"\t";
cout<<endl;
}
}
matrix m;
void main()
{
clrscr();
m.input();
m.mult_matrix();
m.output();
getch();
}