-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathQ17_Transpose.cpp
41 lines (37 loc) · 913 Bytes
/
Q17_Transpose.cpp
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
#include <iostream>
using namespace std;
int main() {
int row,col,i,j;
cout<<"Enter rows and columns of matrix: ";
cin>>row>>col;
int arr[row][col],transpose[col][row];
// Storing matrix elements
cout<<"Enter elements:"<<endl;
for (i=0;i<row;i++) {
for(j=0;j<col;j++){
cin>>arr[i][j];
}
}
// Printing the a matrix
cout <<"\nEntered Matrix: "<< endl;
for (i=0;i<row;i++) {
for (j=0;j<col;j++) {
cout <<" "<<arr[i][j];
if (j==col-1)
cout<<endl<<endl;
}
}
// Computing transpose of the matrix
for(i=0;i<row;i++)
for(j=0;j<col;j++){
transpose[j][i]=arr[i][j];
}
// Printing the transpose
cout<<"\nTranspose of Matrix: " <<endl;
for(i=0;i<col;i++)
for(j=0;j<row;j++){
cout<<" "<<transpose[i][j];
if(j==row - 1)
cout << endl << endl;
}
}