Tuesday, 3 April 2018

Transpose of the Matrix



//Transpose of Matrix in C
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
 int i,j,m,n,a[10][10];
 clrscr();
 printf("Number of Rows\n");
 scanf("%d",&m);
 printf("Number of Columns\n");
 scanf("%d",&n);
//Entry of elements of matrix
 printf("Enter the elements\n");
 for(i=1;i<=m;i++)
 {
  for(j=1;j<=n;j++)
  {
   scanf("%d",&a[i][j]);
  }
 }
//Matrix
 printf("The matrix with %d rows and %d cols is\n",m,n);
 for(i=1;i<=m;i++)
 {
  for(j=1;j<=n;j++)
  {
   printf("\t%d",a[i][j]);
  }
  printf("\n\n");
 }
//Transpose of matrix
 printf("Transpose of the matrix is\n");
 for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
   printf("\t%d",a[j][i]);
  }
  printf("\n\n");
 }
 getch();
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.