-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.cpp
More file actions
111 lines (110 loc) · 1.83 KB
/
Copy pathmatrix.cpp
File metadata and controls
111 lines (110 loc) · 1.83 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
101
102
103
104
105
106
107
108
109
110
#include<iostream>
using namespace std;
class matrix
{
int a[10][10], b[10][10],c[10][10],i,j,k, sum;
public:
void display();
void input();
void addition();
void multiply();
void transpose();
};
void matrix::display()
{
cout<<"Elements of first matrix"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<a[i][j]<<"\t";
cout<<endl;
}
cout<<"Elements of second matrix"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<b[i][j]<<"\t";
cout<<endl;
}
}
void matrix::input()
{
cout<<"Enter the elements of first matrix"<<endl;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
cout<<"Enter the elements of second matrix"<<endl;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>b[i][j];
}
void matrix::addition()
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<a[i][j]+b[i][j]<<"\t";
cout<<endl;
}
}
void matrix::multiply()
{
sum=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
for(k=0;k<3;k++)
{
sum=sum+(a[i])[j]*b[i][j];
c[i][j]=sum;
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<c[i][j]<<"\t";
cout<<endl;
}
}
void matrix::transpose()
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<a[j][i]<<"\t";
cout<<endl;
}
}
int choice()
{
int i;
cout<<"1. Addition\n2. Multiplication\n3. Transpose\n4. Exit"<<endl;
cout<<"Enter your choice"<<endl;
cin>>i;
return i;
}
main()
{
matrix m;
m.input();
m.display();
while(1)
switch(choice())
{
case 1:
cout<<"Addition of two matrices is "<<endl;
m.addition();
break;
case 2:
cout<<"Multiplication of two matrices is "<<endl;
m.multiply();
break;
case 3:
cout<<"Transpose of matrix is "<<endl;
m.transpose();
break;
case 4:
cout<<"Thank you";
exit (0);
default:
cout<<"Invalid Choice"<<endl;
}
}