fork(3) download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. void transpose(double **matrix, int size, double **result)
  7. {
  8. for (int i = 0; i < size; i++)
  9. for (int j = 0; j < size; j++)
  10. result[j][i] = matrix[i][j];
  11. }
  12.  
  13. void print(double **matrix, int size)
  14. {
  15. for (int i = 0; i < size; i++)
  16. {
  17. for (int j = 0; j < size; j++)
  18. cout << setw(2) << matrix[i][j] << ' ';
  19. cout << endl;
  20. }
  21.  
  22. cout << endl;
  23. }
  24.  
  25. int main()
  26. {
  27. double **matrix, **result;
  28. int size = 4;
  29.  
  30. matrix = new double*[size];
  31. result = new double*[size];
  32.  
  33. int cnt = 1;
  34.  
  35. for (int i = 0; i < size; i++)
  36. {
  37. matrix[i] = new double[size];
  38. result[i] = new double[size];
  39.  
  40. for (int j = 0; j < size; j++)
  41. matrix[i][j] = cnt++;
  42. }
  43.  
  44. transpose(matrix, size, result);
  45.  
  46. print(matrix, size);
  47. print(result, size);
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
 1  2  3  4 
 5  6  7  8 
 9 10 11 12 
13 14 15 16 

 1  5  9 13 
 2  6 10 14 
 3  7 11 15 
 4  8 12 16