fork download
  1. #include <iostream> // matrixsort.cpp
  2. using namespace std; int main() // rextester.com/OVFK93608
  3. { setlocale (LC_ALL, "RUS");
  4. srand(time(NULL)); int i,j,k,t;
  5. int n=3, m=5; int a[n][m], b[n][m];
  6.  
  7. for (i=0; i<n; i++)
  8. { for (j=0; j<m; j++)
  9. { a[i][j]= rand() % 9; b[i][j]=a[i][j];
  10. cout << a[i][j] << "\t"; }
  11. cout << endl;
  12. }
  13. cout << endl;
  14.  
  15. for (i=0; i<n; i++)
  16. for (j=0; j<m-1; j++)
  17. for (k=j+1; k<m; k++)
  18. if (a[i][j]>a[i][k]) { t=a[i][j]; a[i][j]=a[i][k]; a[i][k]=t;}
  19.  
  20. for (i=0; i<n; i++)
  21. { for (j=0; j<m; j++) cout << a[i][j] << "\t";
  22. cout << endl;
  23. }
  24. cout << endl;
  25.  
  26. for (i=0; i<n; i++)
  27. { for (j=0; j<m; j++) cout << b[i][j] << "\t";
  28. cout << endl;
  29. }
  30. cout << endl;
  31.  
  32. for (j=0; j<m; j++)
  33. for (i=0; i<n-1; i++)
  34. for (k=i+1; k<n; k++)
  35. if (b[i][j]>b[k][j]) { t=b[i][j]; b[i][j]=b[k][j]; b[k][j]=t;}
  36.  
  37. for (i=0; i<n; i++)
  38. { for (j=0; j<m; j++) cout << b[i][j] << "\t";
  39. cout << endl;
  40. }
  41. cout << endl;
  42. system("pause");
  43. }
  44.  
Success #stdin #stdout #stderr 0.01s 5280KB
stdin
Standard input is empty
stdout
4	6	2	7	8	
8	7	6	8	6	
8	0	8	8	0	

2	4	6	7	8	
6	6	7	8	8	
0	0	8	8	8	

4	6	2	7	8	
8	7	6	8	6	
8	0	8	8	0	

4	0	2	7	0	
8	6	6	8	6	
8	7	8	8	8	

stderr
sh: 1: pause: not found