C Program Code for Transpose of Matrix

Question Types:

Find Transpose of matrix using c programming language ?
How to print transpose of matrix entered by the user using c programming language ?

Program Code:

#include<stdio.h>
// visit informativei.blogspot.com 
int main()
{
int a[3][3] ,b[3][3] , i ,j; // two arrays or matrices and two variables
// code for getting elements from user
printf("Enter 3*3 Matrix A:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
// for displaying matrix A
printf("\nMatrix A : \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\t%d  ",a[i][j]);
}
printf("\n");
}
// code for converting into its transpose
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[j][i]=a[i][j]; // convert rows of matrix a into columns of matrix b
}
}
// code for displaying transpose matrix A
printf("\nTranspose of Matrix B : \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\t%d ",b[i][j]);
}
printf("\n");
}
return 0;
}

// visit informativei.blogspot.com 

Output:

.exe file

1 comment:

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.