20_10

Write a C program to find the transpose of a given matrix.

 Source code:

 /*Write a C program to find the transpose of a given matrix. The transpose of a matrix is a new matrix whose rows are the columns of the original. This makes the columns of the new matrix the rows of the original. Consider a matrix of size 3x3. */

 

#include<stdio.h>

int main(){

  int a[3][3],b[3][3],i,j,k=0,m=3,n=3;


  /* Read an Array a*/

  printf("Enter a matrix:\n");

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

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

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

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

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

          b[i][j]=0;

  for(i=0;i<m;i++){

      for(j=0;j<n;j++){

            b[i][j]=a[j][i];

      }

  }

printf("Transpose of a Matrix");

  for(i=0;i<m;i++){

      printf("\n");

      for(j=0;j<m;j++){

            printf("%d ",b[i][j]);

      }

  }

  return 0;

}

Output:

C program to find the transpose of a given matrix


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...