Search



Friday, 27 February 2015

matrix transpose

  • 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[ ][ ]..
  • 
\begin{bmatrix}
1 & 2 \\
3 & 4 \\
5 & 6 \end{bmatrix}^{\mathrm{T}}
=
\begin{bmatrix}
1 & 3 & 5\\
2 & 4 & 6 \end{bmatrix}


#include<stdio.h>
#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();
}


1 comment:

Guys if you think something is wrong or should be edit than please do comment.