Write a Program to find a Transpose of a given matrix
Transpose of a matrix in C language: This C program prints transpose of a matrix. It is obtained by interchanging rows and columns of a matrix. For example, consider the following 3 X 2 matrix:
1 2
3 4
5 6
Transpose of the matrix:
1 3 5
2 4 6
When we transpose a matrix then its order changes, but for a square matrix, it remains the same.
1 2
3 4
5 6
Transpose of the matrix:
1 3 5
2 4 6
When we transpose a matrix then its order changes, but for a square matrix, it remains the same.
C program to find transpose of a matrix
#include <stdio.h>
int main()
{
int m, n, c, d, matrix[10][10], transpose[10][10];
printf("Enter the number of rows and columns of a matrix\n");
scanf("%d%d", &m, &n);
int main()
{
int m, n, c, d, matrix[10][10], transpose[10][10];
printf("Enter the number of rows and columns of a matrix\n");
scanf("%d%d", &m, &n);
printf("Enter elements of the matrix\n");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &matrix[c][d]);
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
transpose[d][c] = matrix[c][d];
printf("Transpose of the matrix:\n");
for (c = 0; c < n; c++) {
for (d = 0; d < m; d++)
printf("%d\t", transpose[c][d]);
printf("\n");
}
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &matrix[c][d]);
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
transpose[d][c] = matrix[c][d];
printf("Transpose of the matrix:\n");
for (c = 0; c < n; c++) {
for (d = 0; d < m; d++)
printf("%d\t", transpose[c][d]);
printf("\n");
}
return 0;
}
}
No comments:
Post a Comment