-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday4_1_1.cpp
More file actions
80 lines (79 loc) · 1.38 KB
/
day4_1_1.cpp
File metadata and controls
80 lines (79 loc) · 1.38 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
#include<iostream>
#include<stdlib.h>
using namespace std;
class Matrix
{
private:int n;
int m;
int **Arr;
public: Matrix(int n1,int m1)
{
n=n1;
m=m1;
Arr=(int**)malloc(sizeof(int*)*n);
for(int i=0;i<n;i++)
{
*(Arr+i)=(int*)malloc(sizeof(int)*m);
for(int j=0;j<m;j++)
Arr[i][j]=0;
}
}
int getm(){ return m; }
int getn(){ return n; }
void input()
{
printf("Enter The Elements OF MAtrix:\n");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
scanf("%d",*(Arr+i)+j);
}
}
Matrix operator*(Matrix M)
{
Matrix mrr(n,M.m);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
for(int k=0;k<M.n;k++)
{
mrr.Arr[i][k]+=Arr[i][j]*M.Arr[j][k];
}
}
}
return mrr;
}
void display()
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
printf("%d ",*(*(Arr+i)+j));
}
printf("\n");
}
}
};
int main()
{
Matrix A1(5,5);
Matrix A2(5,2);
A1.input();
A2.input();
cout<<"Matrix 1 is\n";
A1.display();
cout<<"Matrix 2 is\n";
A2.display();
if(A1.getm()!=A2.getn())
{
cout<<"Multuplication Not Possible";
return 0;
}
Matrix M(A1.getn(),A2.getm());
M=A1*A2;
cout<<"Result Matrix is\n";
M.display();
return 0;
}