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