This is a C Program which prints the transpose of a given matrix. Transpose of a matrix is obtained by interchanging the rows and columns of a given matrix. |
See the figure below :
PROGRAM :
#include <stdio.h> #include <stdlib.h> int main() { int rows,columns,i,j; printf("Enter order of matrix :\t"); scanf("%d%d",&rows,&columns); int matrix[rows][columns]; printf("\nEnter elements of a matrix\n"); for(i=0;i<rows;i++) { for(j=0;j<columns;j++) { printf("Enter element m%d%d: \t",i+1,j+1); scanf("%d",&matrix[i][j]); } } printf("\nMATRIX is :\n"); for(i=0;i<rows;i++) { for(j=0;j<columns;j++) { printf("%d\t",matrix[i][j]); } printf("\n"); } printf("\nIts TRANSPOSE is:\n"); for(j=0;j<columns;j++) { for(i=0;i<rows;i++) { printf("%d\t",matrix[i][j]); } printf("\n"); } return 0; }
OUTPUT :
C - Transpose of a matrix |