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() % 100;
  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. cout << endl;
  38. }
  39.  
  40. int sum = 0, num;
  41.  
  42. cout << "Write the number: ";
  43. cin >> num;
  44.  
  45. for (int i = 0; i < m; i++) {
  46. for (int j = 0; j < n; j++) {
  47.  
  48. if (arr[i][j] == num)
  49. {
  50. cout << "The number is in the array ";
  51. }
  52. sum += arr[i][j];
  53. }
  54. }
  55.  
  56. cout << "Sum: " << sum;
  57.  
  58. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Matrix:
83	86	77	15	93	
35	86	92	49	21	
62	27	90	59	63	
26	40	26	72	36	
11	68	67	29	82	
Sort Matrix
15	77	83	86	93	
21	35	49	86	92	
27	59	62	63	90	
26	26	36	40	72	
11	29	67	68	82	
Write the number: Sum: 1395