Saturday 24 December 2011

Program to finding TRANSPOSE matrix of a matrix


//program to transpose a matrix//


#include<stdio.h>
#include<conio.h>
#define max 5
void main()
{
  int i,j,m,n,a[max][max],b[max][max];
  clrscr();
  printf("\t\t\t**** TRANSPOSE OF A MATRIX ****");
  printf("\nEnter the no. of rows & coloumns:\n");
  scanf("%d%d",&m,&n);
  printf("Enter the elements of matrix:\n");
  for(i=0;i<m;i++)
  {
     for(j=0;j<n;j++)
     {
      scanf("%d",&a[i][j]);
      b[j][i]=a[i][j];
     }
  }
  printf("\nInputed Matrixes is:\n\n");
  for(i=0;i<m;i++)
  {
    for(j=0;j<n;j++)
    {
      printf("%-4d\t",a[i][j]);  //4 digit right alignment
    }
    printf("\n");
  }
  printf("\nTransposed matrix is:\n\n");
  for(i=0;i<n;i++)
  {
  for(j=0;j<m;j++)
    {
      printf("%-4d\t",b[i][j]); //4 digit right alignment
    }
    printf("\n");
  }
  getch();
}


//Snap shot of output...




No comments:

Post a Comment