/* Transpose of a matrix */
#include<stdio.h>
#include<math.h>
int main()
{
int matrix[10][10], transpose[10][10];
int m, n, c, r;
printf("Enter the number of rows and columns of matrix:\n");
scanf("%d%d", &m, &n);
printf("Enter the %d elements of matrix:\n", m*n);
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
printf("\nEnter value in %dth row and %dth column:", r+1, c+1);
scanf("%d", &matrix[r][c]);
}
}
printf("your matrix:\n");
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
printf("%10d" , matrix[r][c]);
}
printf("\n\n");
}
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
transpose[c][r]=matrix[r][c];
}
}
printf("Transpose of entered matrix :\n");
for(r=0;r<n;r++)
{
for(c=0;c<m;c++)
{
printf("%10d", transpose[r][c]);
}
printf("\n\n");
}
return(0);
}
#include<stdio.h>
#include<math.h>
int main()
{
int matrix[10][10], transpose[10][10];
int m, n, c, r;
printf("Enter the number of rows and columns of matrix:\n");
scanf("%d%d", &m, &n);
printf("Enter the %d elements of matrix:\n", m*n);
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
printf("\nEnter value in %dth row and %dth column:", r+1, c+1);
scanf("%d", &matrix[r][c]);
}
}
printf("your matrix:\n");
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
printf("%10d" , matrix[r][c]);
}
printf("\n\n");
}
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
transpose[c][r]=matrix[r][c];
}
}
printf("Transpose of entered matrix :\n");
for(r=0;r<n;r++)
{
for(c=0;c<m;c++)
{
printf("%10d", transpose[r][c]);
}
printf("\n\n");
}
return(0);
}
Comments
Post a Comment