Friday 23 September 2016

Matrix Transpose

/* Transpose the matrix */
#include<stdio.h>

int main()
{
int a[4][4],i,j,b;

for(i=0;i<4;i++)
{
printf("\nEnter elements of %d row of Matrix: ",i+1);
for(j=0;j<4;j++)
scanf("%d",&a[i][j]);
}

for(i=0;i<4;i++)
{
for(j=i+1;j<4;j++)
{
b=a[i][j];
a[i][j]=a[j][i];
a[j][i]=b;
}
}

printf("\nTransposed Matrix:\n\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%4d",a[i][j]);
printf("\n");
}
return 0;
}

No comments:

Post a Comment

Featured post

The Thrill of Programming: Exploring the Satisfaction Behind the Code

Different individuals find satisfaction in programming for various reasons. Here are some common factors that tend to bring satisfaction to ...