fork download
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8. const int m = 5, n = 5;
  9. int arr[m][n]{};
  10.  
  11. for (int i = 0; i < m; i++){
  12. for (int j = 0; j < n; j++){
  13. arr[i][j] = rand() % 30;
  14. }
  15. }
  16.  
  17. cout << "Matrix:" << endl;
  18. for (int i = 0; i < m; i++){
  19. for (int j = 0; j < n; j++){
  20. cout << arr[i][j] << "\t";
  21. }
  22. cout << endl;
  23. }
  24.  
  25. for (int i = 0; i < m; i++)
  26. {
  27. sort(arr[i], arr[i] + n);
  28. }
  29.  
  30. cout << "Sort Matrix" << endl;
  31. for (int i = 0; i < m; i++)
  32. {
  33. for (int j = 0; j < n; j++)
  34. {
  35. cout << arr[i][j] << "\t";
  36.  
  37. }
  38. cout << endl;
  39. }
  40. int sum = 0;
  41. for (int i = 0; i < m; i++)
  42. {
  43. for (int j = 0; j < n; j++)
  44. {
  45. sum += arr[i][j];
  46. }
  47.  
  48. }
  49. cout << "Sum: " << sum;
  50. }
Success #stdin #stdout 0.01s 5264KB
stdin
Standard input is empty
stdout
Matrix:
13	16	27	25	23	
25	16	12	9	1	
2	7	20	19	23	
16	0	6	22	16	
11	8	27	9	2	
Sort Matrix
13	16	23	25	27	
1	9	12	16	25	
2	7	19	20	23	
0	6	16	16	22	
2	8	9	11	27	
Sum: 355