- In this program , we have to input the elements in a 2D array which is a[ ][ ]find its corresponding transpose. So , the no. of rows & columns are stored in m & n respectively . Then the values of matrix a[ ][ ] is inserted. During transpose , the rows of matrix becomes the column of matrix & columns becomes rows . i.e. a[i][j] becomes a[j][i] . So, using this procedure & matrices are transposed & result is stored in matrix c[ ][ ]..

#include<conio.h>
void main()
{ int a[10][10],trans[10][10],i=0,j=0,m,n;
clrscr();
printf("\n program to tranpose a matrix");
printf("\n enter no. of rows : ");
scanf("%d",&m);
printf(" enter no. of columns : ");
scanf("%d",&n);
printf("\n now enter them : \n");
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
{ printf("enter a[%d][%d] = ",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\n displaying matrix : \n");
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
{ printf("\t a[%d][%d] = %d",i,j,a[i][j]);
trans[j][i] = a[i][j];
}
printf("\n");
}
printf("after transposing matrix = \n");
for(i=0;i<n;i++)
{ for(j=0;j<m;j++)
{ printf("\t a[%d][%d] = %d",i,j,trans[i][j]);
}
printf("\n");
}
getch();
}

thanks,it works
ReplyDelete