/* 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;
}
Matrix Multiplication
/* Matrix multiplication */
#include<stdio.h>
int main()
{
int arr1[3][3],arr2[3][3],arr3[3][3]={0},i,j,k;
printf("Type a matrix of 3 rows & 3 colomns :\n");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&arr1[i][j]);
printf("Type another matrix of 3 rows & 3 colomns :\n");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&arr2[i][j]);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
arr3[i][j]=arr3[i][j]+arr1[i][k]*arr2[k][j];
}
}
printf("\n\nOutput:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%5d",arr3[i][j]);
printf("\n\n");
}
return 0;
}
Just Give Your Feedback ConversionConversion EmoticonEmoticon