Pages

Tuesday 5 March 2019

Program to illustrate transpose of a matrix

Program to illustrate transpose of a matrix
#include <stdio.h>
  void main()
    {
       int row, col, i, j, first[10][10], trans[10][10];
       printf("Enter the number of rows and columns of first matrix\n");
       scanf("%d%d", &row, &col);
       printf("Enter the %d elements of first matrix\n",row * col);
       for (i = 0; i < row; i++)
          {
          for (j = 0; j < col; j++)
            {
             scanf("%d", &first[i][j]);
            }
          }
       printf("\nFirst matrix :\n");
       for (i = 0; i < row; i++)
         {
          for (j = 0; j < col; j++)
            {
             printf("%d\t", first[i][j]);
            }
           printf("\n");
         }
        for (i = 0; i < row; i++)
        {
          for (j = 0 ; j < col; j++)
          {
             trans[i][j] = first[j][i];
          }
          printf("\n");
       }
       printf("\n Transpose of first matrix\n ");
       for (i = 0; i < row; i++)
         {
          for (j = 0; j < col; j++)
            {
             printf("%d\t", trans[i][j]);
            }
           printf("\n");
         }
      
  }

output:

No comments:

Post a Comment

Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...