Write a c program to find out transport of a matrix








C program for transpose of a matrix
C program to find transpose of given matrix

#include<stdio.h>
int main(){
  int a[10][10],b[10][10],i,j,k=0,m,n;
  printf("\nEnter the row and column of matrix");
  scanf("%d %d",&m,&n);
  printf("\nEnter the First matrix->");
  for(i=0;i<m;i++)
      for(j=0;j<n;j++)
           scanf("%d",&a[i][j]);
  printf("\nThe matrix is\n");
  for(i=0;i<m;i++){
      printf("\n");
      for(j=0;j<m;j++){
           printf("%d\t",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("\n%d",b[i][j]);
      }
  }
  printf("\n\nTraspose of a matrix is -> ");
  for(i=0;i<m;i++){
      printf("\n");
      for(j=0;j<m;j++){
           printf("%d\t",b[i][j]);
      }
  }
  return 0;
}




Alogrithm:
**







8 comments:

Anonymous said...

i guess the for loop bfore b[i][j]=0 nd bfore transposing shud hav i<n nd j<m am i rite?

GOBINATH said...
This comment has been removed by the author.
Unknown said...

i think initially for b[i][j] it should be scanf not printf because computer should store the matrix b first

Anonymous said...

Good Code !

Unknown said...

hello
i want c program to transpose of a matrix by using functions

Unknown said...

#include
void main()
{
int a[10][10],i,j,m,n;
printf("enter m(row) value");
scanf("%d",&m);
printf("enter n(column) value ");
scanf("%d",&n);
printf("enter matrix walues");
for(i=0;i<m;i++){
for(j=0;j<n;j++){
printf("enter a[%d][%d]",i,j);
scanf("%d",&a[i][j]);
}}
printf("after transpose");
for(i=0;i<m;i++){
for(j=0;j<n;j++){
printf("a[%d][%d]:%d",j,i,a[j][i]);
}
}
}

Unknown said...

I want a c program to find out transpose of two user given matrices

Unknown said...

#include
#include

int main(void)
{
int i , j;
int r, c ;

//Asking for no or rows and columns required
printf("Enter the Number of rows of matrix 1: ");
scanf("%d",&r);
printf("Enter the Number of columnss of matrix 1: ");
scanf("%d",&c);
int array[r][c];
int transpose[c][r];

//Inputs matrix's elemenst
printf("Enter elements of the matrix: \n");
for (i = 0; i<r; i++)
{
for (j = 0; j<c; j++)
{
scanf("%d",&array[i][j]);
}
}


//Transpose of the matrix
for (i = 0 ; i<r; i++)
{
for (j = 0 ; j<c; j++)
{
transpose[j][i] = array[i][j];
}
}

//Printing the transposed matrix
printf("\n");
for (i = 0; i<c; i++)
{
for (j = 0; j<r; j++)
{
printf("%d ",transpose[i][j]);
}
printf("\n");
}


return 0;
}