C++ Program to Display Transpose of Matrix

In this program, you will learn to display transpose of a matrix (entered by the user). A matrix which is formed by turning all the rows of a given matrix into columns and vice-versa. The transpose of matrix A is written AT.

Example: Program to Display Transpose of Matrix

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

#include <iostream>

using namespacestd;

intmain()

{

inta[10][10],trans[10][10],r,c,i,j;

cout<<"Enter rows and columns of matrix: ";

cin>>r>>c;

// Storing element of matrix entered by user in array a[][].

cout<<endl<<"Enter elements of matrix: "<<endl;

for(i=0;i<r;++i)

{

for(j=0;j<c;++j)

{

cin>>a[i][j];

}

}

// Displaying the matrix a[][]

cout<<endl<<"Entered Matrix: "<<endl;

for(i=0;i<r;++i)

{

for(j=0;j<c;++j)

{

cout<<" "<<a[i][j];

if(j==c-1)

cout<<endl<<endl;

}

}

// Finding transpose of matrix a[][] and storing it in array trans[][].