C Program to find Transpose of a Matrix
This is the C program to find the transpose of a matrix.
A matrix which is formed by turning all the rows of a given matrix into columns and vice-versa.
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],i,j,r,c;
printf("Enter the no. of rows for Matrix :");
scanf("%d",&r);
printf("Enter the no. of columns for Matrix :");
scanf("%d",&c);
/* * * * * READ MATRIX * * * * */
printf("nnNow enter the Matrix A[%d][%d] :-nn",r,c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("Row[%d] Column[%d] :",i,j);
scanf("%d",&a[i][j]);
}
}
/* * * * * PRINT MATRIX * * * * */
printf("nn");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%5d",a[i][j]);
}
printf("n");
}
/* * * * * TRANSPOSE MATRIX * * * * */
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
b[j][i] = a[i][j];
}
}
/* * * * * PRINT TRANSPOSED MATRIX * * * * */
printf("nn Now the Transposed Matrix is :-nn");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%5d",b[i][j]);
}
printf("n");
}
}
Recent Comments