C Program For TRANSPOSE MATRIX
This c program prints transpose of a matrix. It is obtained by interchanging rows
and columns of a matrix. For example if a matrix is
1 2
3 4
5 6
then transpose of above matrix will be
1 3 5
2 4 6
When we transpose a matrix then the order of matrix changes, but for a square
matrix order remains same.
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,r,c,a[10][10];
clrscr();
printf("Enter r and c value:");
scanf("%d%d",&r,&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
printf("\n\n");
if(r==c)
{
printf("transpose matrix");
printf("\n");
for(i=1;i<=c;i++)
{
for(j=1;j<=r;j++)
{
printf("%d",a[j][i]);
}
printf("\n");
}
}
else
{
printf("not possible");
}
getch();
}

0 comments:
Post a Comment