Transpose a non-square matrix.

#include <stdio.h>

int main(void)
{
int arr[2][4], trans[4][2], i, j;

for(i = 0 ; i < 2 ; i++)
{
printf("\nRow %d\n", i + 1);
for(j = 0 ; j < 4 ; j++)
{
printf("\tValue %d :", j + 1);
scanf("%d", &arr[i][j]);
}
}

printf("\nDisplaying original matrix : ");
for(i = 0 ; i < 2 ; i++)
{
printf("\n");
for(j = 0 ; j < 4 ; j++)
printf("\t%d", arr[i][j]);
}

for(i = 0 ; i < 2 ; i++)
{
for(j = 0 ; j < 4 ; j++)
{
trans[j][i] = arr[i][j];
}
}

printf("\nDisplaying transposed matrix : ");
for(i = 0 ; i < 4 ; i++)
{
printf("\n");
for(j = 0 ; j < 2 ; j++)
printf("\t%d", trans[i][j]);
}

return 0;
}

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin