Monday, June 18, 2012

To find the transpose of a matrix


/* Program to find the transpose of a matrix */

#include<stdio.h>

#include<conio.h>

void main()

{

  int mat[100][100],transp[100][100];

  int i,j,row,col;

  clrscr();

  printf("Enter the order of Matrix:\n");

  scanf("%d%d",&row,&col);

  printf("\nEnter the elements of Matrix-->\n");

  for(i=0;i<row;i++)

  {

    for(j=0;j<col;j++)

    {

      scanf("%d",&mat[i][j]);

    }

  }

  printf("\n\nGiven Matrix:\n");

  for(i=0;i<row;i++)

  {

    for(j=0;j<col;j++)

    {

      printf("\t%d",mat[i][j]);

    }

    printf("\n");

  }

  printf("\nTranspose of the Given Matrix-->\n");

  for(i=0;i<row;i++)

  {

    for(j=0;j<col;j++)

    {

      transp[i][j]=mat[j][i];

      printf("\t%d",transp[i][j]);

    }

    printf("\n");

  }

  getch();

}

 

OUTPUT

Enter the order of Matrix:

3

3

 

Enter the elements of Matrix-->

1

2

4

3

2

5

1

2

3

 

 

Given Matrix:

        1       2       4

        3       2       5

        1       2       3

 

Transpose of the Given Matrix-->

        1       3       1

        2       2       2

        4       5       3

 

No comments:

Post a Comment

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