fork download
  1. #include<stdio.h>
  2.  
  3. double **transpose(int row, int col, double orig[row][col], double result[col][row]){
  4. int i,j;
  5.  
  6. double temp;
  7.  
  8. for(i=0;i<row;i++){
  9. for(j=0;j<col;j++){
  10. temp=orig[i][j];
  11. orig[i][j]=result[j][i];
  12. result[j][i]=temp;
  13. }
  14. }
  15. return result;
  16. }
  17.  
  18. void show(int r, int c, double arr[r][c]){
  19. int i,j;
  20. for (i=0;i<r;i++){
  21. for (j=0;j<c;j++){
  22. printf("%lf ", arr[i][j]);
  23. }
  24. printf("\n");
  25. }
  26. }
  27. int main(){
  28. int r;
  29. int c;
  30.  
  31. scanf("%i", &r);
  32. scanf("%i", &c);
  33.  
  34. double a[r][c],b[c][r];
  35.  
  36. int i,j;
  37.  
  38. for(i=0;i<r;i++){
  39. for(j=0;j<c;j++){
  40. scanf("%lf", &a[i][j]);
  41. }
  42. }
  43.  
  44. show(c,r,transpose(r,c,a,b));
  45. return 0;}
  46.  
Success #stdin #stdout 0s 4224KB
stdin
2 2 1 2 3 4
stdout
1.000000 3.000000 
2.000000 4.000000