fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. int main (){
  5. int n, m, arr[100][100];
  6. cin >> n >> m;
  7. for(int i = 0; i < n; i++){
  8. for(int j = 0; j < m; j++){
  9. cin >> arr[i][j];
  10. }
  11. }
  12. for(int i = 0; i < n; i++){
  13. for(int j = 0; j < m; j++){
  14. for(int d = j + 1; d < m; d++){
  15. if(arr[i][j] > arr[i][d]){
  16. swap (arr[i][j], arr[i][d]);
  17. }
  18. }
  19. }
  20. }
  21. cout << "Sorted matrix: " << "\n";
  22. for(int i = 0; i < n; i++){
  23. for(int j = 0; j < m; j++){
  24. cout << arr[i][j] << " ";
  25. }
  26. cout << endl;
  27. }
  28. }
Success #stdin #stdout 0.01s 5312KB
stdin
3 4
5 4 9 10
9 6 3 7
2 0 4 5
stdout
Sorted matrix: 
4 5 9 10 
3 6 7 9 
0 2 4 5