Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 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. for (int i = 1; i < n + 1; i++)
  63. {
  64. if (b[i][n+1] > b[i-1][n+1])
  65. {
  66. for (int j = 0; j < n ; j++)
  67. {
  68. t = b[i][j];
  69. b[i][j] = b[i - 1][j];
  70. b[i - 1][j] = t;
  71.  
  72. }
  73. }
  74. }
  75.  
  76. for (int i = 0; i < n; i++)
  77. {
  78.  
  79. for (int j = 0; j < n; j++)
  80. {
  81. cout << setw(3) << b[i][j];
  82. }
  83. cout << endl;
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement