Transpose a matrix using c++ program

This c program prints transpose of a matrix. It is obtained by interchanging rows and columns of a matrix. For example if a matrix is
1 2
3 4
5 6
then transpose of above matrix will be
1 3 5
2 4 6
When we transpose a matrix then the order of matrix changes, but for a square matrix order remains same.


Algorithm :
Matrix Transpose means changing the order or arrangement of a matrix. If A be the given matrix, then the matrix formed by interchanging the columns and rows of the matrix A without changing the value of elements is called as transpose of a matrix. If Am×n = [aij], then AT(n×m) = [aji] i.e. the (i,j)th element of A is the (j,i)th element of AT. So, in A and AT,
  • ith column of AT = ith row of A
  • jth row of AT = jth column of A
  • In A and AT, the diagonal elements are equal.


C++ program code :



Output of program :

Enter the number of Rows of Matrix 1 : 3

Enter the number of Columns of Matrix 1 : 2
Enter the Element a[0][0] : 1
Enter the Element a[0][1] : 2
Enter the Element a[1][0] : 3
Enter the Element a[1][1] : 4
Enter the Element a[2][0] : 5
Enter the Element a[2][1] : 6

Matrix elements :
1 2
3 4
5 6

Matrix elements :
1 3 5
2 4 6

Date - 1/26/2013-@author Y.ACHCHUTHAN -cpp90.blogspot.com
Press any key to continue . . .

3 comments:

Copyright © 2010-2019 C++ Examples

Designed by Templateism. Built with Blogger Templates.