Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<time.h>
- #include<iomanip>
- #include <iostream>
- using namespace std;
- int const n = 5;
- int sum = 0;
- int k = 1;
- int f;
- int z=1;
- int t;
- int max = 0;
- int maxsum = 0;
- int main()
- {
- int arry[n][n];
- int* ptr[n];
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- arry[i][j] = (rand() % 10) - 4;
- cout << setw(4) << arry[i][j];
- }
- cout << endl;
- }
- cout << endl;
- int** b = new int* [n];
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n + 1; j++)
- {
- b[i] = new int[n + 1];
- }
- }
- for (int i = 0; i < n; i++)
- {
- max = 0;
- for (int j = 0; j < n; j++)
- {
- if ((arry[i][j] < 0) && (j % 2 == 0))
- {
- max += arry[i][j];
- }
- b[i][j] = arry[i][j];
- }
- b[i][n] = max;
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n + 1; j++)
- {
- cout << setw(3) << b[i][j];
- }
- cout << endl;
- }
- cout << endl;
- while (z == 1)
- {
- for (int i = 1; i < n; i++)
- {
- z = 0;
- if (b[i][n ] < b[i - 1][n ])
- {
- z = 1;
- for (int j = 0; j < n+1; j++)
- {
- t = b[i][j];
- b[i][j] = b[i - 1][j];
- b[i - 1][j] = t;
- }
- }
- }
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cout << setw(3) << b[i][j];
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement