A matrix's transpose is determined by converting its rows into columns or columns into rows. The letter "T" in the superscript of the supplied matrix denotes the transpose of the matrix.
#include<stdio.h>
#include<conio.h>
int main() {
int a[10][10], transpose[10][10], r, c;
printf("Enter the rows and columns: ");
scanf("%d %d", &r, &c);
// asssigning elements to the matrix
printf("\nEnter the elements of the matrix:\n");
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j) {
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}
// Display the matrix
printf("\n Entered matrix is : \n");
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j) {
printf("%d ", a[i][j]);
if (j == c - 1)
printf("\n");
}
// compute the transpose
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j) {
transpose[j][i] = a[i][j];
}
// Display the transpose
printf("\nTranspose of matrix is :\n");
for (int i = 0; i < c; ++i)
for (int j = 0; j < r; ++j) {
printf("%d ", transpose[i][j]);
if (j == r - 1)
printf("\n");
}
getch();
return 0;
}
Enter the number of rows and columns: 3
4
Enter the elements of the matrix:
Enter element a11: 1
Enter element a12: 2
Enter element a13: 5
Enter element a14: 4
Enter element a21: 7
Enter element a22: 8
Enter element a23: 9
Enter element a24: 6
Enter element a31: 3
Enter element a32: 2
Enter element a33: 1
Enter element a34: 5
Entered matrix is :
1 2 5 4
7 8 9 6
3 2 1 5
Transpose of matrix is :
1 7 3
2 8 2
5 9 1
4 6 5
--------------------------------
Process exited after 15.77 seconds with return value 0
Press any key to continue . . .