Advertisement
Guest User

Untitled

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