Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1.  
  2. #include<time.h>
  3. #include<iomanip>
  4. #include <iostream>
  5. using namespace std;
  6. int const n = 5;
  7. int sum = 0;
  8. int k = 1;
  9. int f;
  10. int z=1;
  11. int t;
  12. int max = 0;
  13. int maxsum = 0;
  14. int main()
  15. {
  16.  
  17. int arry[n][n];
  18. int* ptr[n];
  19. for (int i = 0; i < n; i++)
  20. {
  21. for (int j = 0; j < n; j++)
  22. {
  23. arry[i][j] = (rand() % 10) - 4;
  24. cout << setw(4) << arry[i][j];
  25. }
  26. cout << endl;
  27. }
  28. cout << endl;
  29. int** b = new int* [n];
  30. for (int i = 0; i < n; i++)
  31. {
  32. for (int j = 0; j < n + 1; j++)
  33. {
  34. b[i] = new int[n + 1];
  35. }
  36. }
  37. for (int i = 0; i < n; i++)
  38. {
  39. max = 0;
  40. for (int j = 0; j < n; j++)
  41. {
  42. if ((arry[i][j] < 0) && (j % 2 == 0))
  43. {
  44. max += arry[i][j];
  45.  
  46. }
  47. b[i][j] = arry[i][j];
  48. }
  49. b[i][n] = max;
  50.  
  51. }
  52. for (int i = 0; i < n; i++)
  53. {
  54. for (int j = 0; j < n + 1; j++)
  55. {
  56. cout << setw(3) << b[i][j];
  57. }
  58. cout << endl;
  59. }
  60. cout << endl;
  61.  
  62.  
  63.  
  64.  
  65. while (z == 1)
  66. {
  67.  
  68. for (int i = 1; i < n; i++)
  69. {
  70. z = 0;
  71. if (b[i][n ] < b[i - 1][n ])
  72. {
  73. z = 1;
  74. for (int j = 0; j < n+1; j++)
  75. {
  76. t = b[i][j];
  77. b[i][j] = b[i - 1][j];
  78. b[i - 1][j] = t;
  79.  
  80. }
  81. }
  82. }
  83.  
  84. }
  85.  
  86.  
  87. for (int i = 0; i < n; i++)
  88. {
  89.  
  90. for (int j = 0; j < n; j++)
  91. {
  92. cout << setw(3) << b[i][j];
  93. }
  94. cout << endl;
  95. }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement