C program for Transpose of Matrix: The source code of this program provides you an interchangeable matrix output. Transpose matrix means, interchanging rows and columns of a particular matrix at the time of execution. This C program consists of an example code with explanation also. An example program is given at the bottom. Before going to this topic, just check the Matrix addition and the Matrix multiplication programs also.
TRANSPOSE A MATRIX IN C
This code is based on arrays concept. And this C program is used to change the dimensions of a matrix by changing the row and Column of matrix format. For example, given input matrix format is
2 4
7 9
5 8
after transpose of dimension is
2 7 5
4 9 8
Transpose matrix program:
Q: Write a program to find the transpose of given matrix in C using arrays.
/* Header files section © http://students3k.com */ #include<stdio.h> #include<conio.h> void main() { //Program variables int m1[40][40],m2[40][40],j,i,temp,nu,nu1,nu2,nu3; clrscr();//Function to clear previous function printf("Enter the dimension of matrix");//Display function scanf("%d%d",&n,&n1);//Getting input function printf("\enter the matrix dimension format"); for(i=0;i<n;i++)//Looping statement { for(j=0;j<n1;j++)//Nested for loop { scanf("%d",&m1[i][j]); // © http://students3k.com } } printf("\n\n the matrix format is :"); for(i=0;i<nu;i++) { printf("\n"); for(j=0;j<nu1;j++) { printf("%d\t",m1[i][j]); } } printf("\n"); printf("\n The transpose the dimension of matrix is"); for(i=0;i<nu;i++) { printf("\n"); for(j=0;j<nu1;j++) { printf("%d\t",m1[j][i]); } } getch(); }