Write a program to read a matrix of size m x n and print its transpose.
#include <stdio.h>
void main()
{
int A[50][50],i,j,r,c;
clrscr();
printf("Enter the no. of Rows of Matrix:");
scanf("%d",&r);
printf("Enter the no. of column of Matrix:");
scanf("%d",&c);
printf("Enter the elements of Matrix Row wise\n");
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf("%d",&A[i][j]);
printf("Transpose of Matrix\n");
for(i=1;i<=c;i++)
{
for(j=1;j<=r;j++)
printf("%d ",A[j][i]);
putchar('\n');
}
getch();
}
#include <stdio.h>
void main()
{
int A[50][50],i,j,r,c;
clrscr();
printf("Enter the no. of Rows of Matrix:");
scanf("%d",&r);
printf("Enter the no. of column of Matrix:");
scanf("%d",&c);
printf("Enter the elements of Matrix Row wise\n");
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf("%d",&A[i][j]);
printf("Transpose of Matrix\n");
for(i=1;i<=c;i++)
{
for(j=1;j<=r;j++)
printf("%d ",A[j][i]);
putchar('\n');
}
getch();
}
No comments:
Post a Comment