Article by: Manish Methani
Last Updated: September 26, 2021 at 10:04am IST
The transpose of a matrix is obtained by changing its rows into columns and its columns into rows. A rectangular array of numbers or functions that are arranged in the form of rows and columns is called a matrix.
#include <stdio.h> #define NUMBEROFROWS 10 #define NUMBEROFCOLS 10 int main() { int matrix[NUMBEROFROWS][NUMBEROFCOLS]; int i,j,row,col; printf("Enter number of Rows :"); scanf("%d",&row); printf("Enter number of Cols :"); scanf("%d",&col); printf("Enter matrix elements :"); for(i=0;i< row;i++) { for(j=0;j< col;j++) { printf("Enter element [%d,%d] : ",i+1,j+1); scanf("%d",&matrix[i][j]); } } printf("Transpose Matrix is :"); for(i=0;i< col;i++) { for(j=0;j < row;j++) { printf("%d ",matrix[j][i]); /*print elements*/ } printf(" "); /*after each row print new line*/ } return 0; }
Enter number of Rows :2 Enter number of Cols :3 Enter matrix elements : Enter element [1,1] : 10 Enter element [1,2] : 11 Enter element [1,3] : 12 Enter element [2,1] : 13 Enter element [2,2] : 14 Enter element [2,3] : 15 Transpose Matrix is : 10 13 11 14 12 15