Wednesday 26 October 2011

implementation of transpose of matrix

/*
ALGORITHM:

Transpose(a,m,n)
1 for(i= 1 to m)
            for(j= 1 to n)
            b[i][j]= a[j][i]
2 for (i=1to m)
            for (j= 1to n)
            a[i][j]= b[i][j]
3 exit.
*/
//program implemented by shadab khan
#include <stdio.h>
#include <conio.h>
Void main()
{
int a[10][10],b[10][10],i,j,m,n;
clrscr();
printf("Enter the order of the matrix\n");
printf("No. of rows : \n");
scanf("%d",&n);
printf("No. of columns :\n ");
scanf("%d",&m);
printf("Enter the matrix elements\n");
for(i=0;i<=n-1;i++)
{
            for(j=0;j<=m-1;j++)
            {
                        scanf("%d\n",&a[i][j]);
                        b[j][i] = a[i][j];
            }
}
printf("Matrix A was\n ");
for(i=0;i<=n-1;i++)
{
            for(j=0;j<=m-1;j++)
            {
                        printf("%d\n",a[i][j]);
            }
}
printf("Transpose of matrix A is \n");
for(i=0;i<=m-1;i++)
{
            for(j=0;j<=n-1;j++)
            {
            printf("%d\n",b[i][j]);
            }
}
getch( );
}

No comments:

Post a Comment