-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtranspose_of_matrix.cpp
More file actions
106 lines (87 loc) · 1.93 KB
/
transpose_of_matrix.cpp
File metadata and controls
106 lines (87 loc) · 1.93 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
//C++ program with class Matrix and write operations for Read, Show and Transpose of Matrix.
#include<iostream>
using namespace std;
class matrix
{
private:
int a[50][50], b[50][50], cols, rows;
public:
void read()
{
cout<<"Enter no. of rows in the matrix : ";
cin>>rows;
cout<<"Enter no. of columns in the matrix : ";
cin>>cols;
cout<<"Enter matrix elements :\n";
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
cin>>a[i][j];
}
cout<<"\n";
}
}
void transpose();
void show()
{
cout<<"The matrix is :\n ";
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
cout<<a[i][j]<<" ";
}
cout<<"\n";
}
}
};
void matrix::transpose()
{
for(int i=0;i<rows;++i)
{
for(int j=0;j<cols;++j)
{
b[j][i]=a[i][j];
}
}
cout<<"Transposed matrix is : \n";
for(int i=0;i<cols;++i)
{
for(int j=0;j<rows;++j)
{
cout<<b[i][j]<<" ";
if (j == rows - 1)
{
cout<<"\n";
}
}
cout<<"\n";
}
}
int main()
{
matrix m1;
m1.read();
int ch;
do
{
cout<<"Enter your choice :\n1.Display\n2.Transpose\n3.EXIT\n";
cin>>ch;
switch(ch)
{
case 1:
m1.show();
break;
case 2:
m1.transpose();
break;
case 3:
cout<<"*****EXIT*****";
break;
default:
cout<<"~~~~~Wrong choice enter again~~~~~";
}
}while(ch!=3);
return 0;
}