Program
#include <stdio.h>
void main()
{
int m, n, col, row, matrix[10][10], transpose[10][10];
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of matrix\n");
for (row=0;row<m;row++)
for(col=0;col<n;col++)
scanf("%d",&matrix[row][col]);
for (row=0;row<m;row++)
for(col=0;col<n;col++)
transpose[col][row] = matrix[row][col];
printf("Transpose of entered matrix :-\n");
for (row=0;row<n;row++)
{
for(col=0;col<m;col++)
printf("%d\t",transpose[row][col]);
printf("\n");
}
}
Output
Enter the number of rows and columns of matrix
3
2
Enter the elements of matrix
1 2
3 4
5 6
Transpose of entered matrix :-
1 3 5
2 4 6
#include <stdio.h>
void main()
{
int m, n, col, row, matrix[10][10], transpose[10][10];
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of matrix\n");
for (row=0;row<m;row++)
for(col=0;col<n;col++)
scanf("%d",&matrix[row][col]);
for (row=0;row<m;row++)
for(col=0;col<n;col++)
transpose[col][row] = matrix[row][col];
printf("Transpose of entered matrix :-\n");
for (row=0;row<n;row++)
{
for(col=0;col<m;col++)
printf("%d\t",transpose[row][col]);
printf("\n");
}
}
Output
Enter the number of rows and columns of matrix
3
2
Enter the elements of matrix
1 2
3 4
5 6
Transpose of entered matrix :-
1 3 5
2 4 6
No comments:
Post a Comment