WRITE A C PROGRAM TO TRANSPOSE A MATRIX
#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,i,j,a[10][10],b[10][10];
printf("Enter the number of rows and column:");
scanf("%d%d",&m,&n);
printf("Enter the matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",a[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
b[j][i]=a[i][j];
}
}
printf("The transpose matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d",b[i][j]);
}
}
getch();
}
Output:
Enter the number of rows and column:3
2
Enter the matrix:
1 2
4 5
7 8
The transpose matrix:
1 4 7
2 5 8
#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,i,j,a[10][10],b[10][10];
printf("Enter the number of rows and column:");
scanf("%d%d",&m,&n);
printf("Enter the matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",a[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
b[j][i]=a[i][j];
}
}
printf("The transpose matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d",b[i][j]);
}
}
getch();
}
Output:
Enter the number of rows and column:3
2
Enter the matrix:
1 2
4 5
7 8
The transpose matrix:
1 4 7
2 5 8
No comments:
Post a Comment