MCPcopy Create free account
hub / github.com/Rustam-Z/cpp-programming / transpose

Function transpose

Lab_09/Source1.cpp:62–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62void transpose()
63{
64 system("cls");
65 cout << "\t\tTRANSPOSE OF MATRIX\n";
66 int a[5][5], trans[5][5], r, c, i, j;
67 cout << "Please input information about 2D array: " << endl;
68 cout << "Rows (max 5): ";
69 cin >> r;
70 cout << "Columns (max 5): ";
71 cin >> c;
72 // Storing element of matrix entered by user in array
73 if (r > 0 && r <= 5 && c > 0 && c <= 5)
74 {
75 cout << "Enter elements of matrix: " << endl;
76 for (i = 0; i < r; ++i)
77 for (j = 0; j < c; ++j)
78 {
79 cin >> a[i][j];
80 }
81 // Displaying the matrix
82 cout << "Entered Matrix: " << endl;
83 for (i = 0; i < r; ++i)
84 for (j = 0; j < c; ++j)
85 {
86 cout << " " << a[i][j];
87 if (j == c - 1)
88 cout << endl
89 << endl;
90 }
91 // Finding transpose of matrix
92 for (i = 0; i < r; ++i)
93 for (j = 0; j < c; ++j)
94 {
95 trans[j][i] = a[i][j];
96 }
97 // Displaying the transpose
98 cout << "Transpose of Matrix: " << endl;
99 for (i = 0; i < c; ++i)
100 for (j = 0; j < r; ++j)
101 {
102 cout << " " << trans[i][j];
103 if (j == r - 1)
104 cout << endl
105 << endl;
106 }
107 cout << endl;
108 cout << "Do you want to try again? (Yes = 1, No = Any Key)\n";
109 string respond;
110 cout << "Your choice: ";
111
112 cin >> respond;
113 if (respond == "1")
114 {
115 system("cls");
116 transpose();
117 }
118 else
119 {

Callers 1

main22Function · 0.85

Calls 1

mainFunction · 0.70

Tested by

no test coverage detected