-3

How to do Matrix Transposition in C language?Program will ask the user for the number of rows and columns and the data for the matrix. The output will be the transpose of the matrix.

Steele
  • 1
  • 3
  • Are you asking how to switch the row and column indices of a matrix? Or do you want to know how to do this with a linear algebra library? – shayaa Oct 14 '16 at 08:52
  • the first one how to code it in C – Steele Oct 14 '16 at 08:54
  • There are several answers [on this older thread](http://stackoverflow.com/questions/16737298/what-is-the-fastest-way-to-transpose-a-matrix-in-c) – shayaa Oct 14 '16 at 09:00

2 Answers2

0

Let's say we have a matrix(x,y), where x is rows and y is columns. If you need only to show the transpose of the matrix you can simply switch x and y while printing it (so you will be printing rows as columns and columns as rows). The output will be the transpose of the matrix.

Genn
  • 1
  • 1
0

Here it is some code

// define the lenght of the matrix
int lenght_x = 3;
int lenght_y = 3;
// matrix
int mat[lenght_x][lenght_y];
// indexes
int x,y;

// reading values from user input
for(y=0; y<lenght_y; y++){
  for(x=0; x<lenght_x; x++){
    scanf("%d",&mat[x][y]);
  }
}

// printing the matrix
for(y=0; y<lenght_y; y++){
  for(x=0; x<lenght_x; x++){
    printf("%d  ",mat[x][y]);
  }
  printf("\n");
}

printf("\n");

// printing the tranpose of the matrix
for(y=0; y<lenght_y; y++){
  for(x=0; x<lenght_x; x++){
    printf("%d  ",mat[y][x]);   // !!! HERE I SWITCHED X AND Y
  }
  printf("\n");
}

I think it's very simple... however there should be several answers on older thread

Genn
  • 1
  • 1