Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- void main()
- {
- setlocale(LC_ALL, "rus");
- int n = 4, **a, *summ;
- int buf;
- a = new int*[n];
- summ = new int[n];
- for (int i = 0; i < n; i++)
- {
- cout << endl;
- a[i] = new int[n];
- for (int j = 0; j < n; j++)
- {
- a[i][j] = rand() % 10 - 5;
- cout << a[i][j] << " ";
- }
- }
- for (int i = 0; i < n; i++)
- {
- summ[i] = 0;
- for (int j = 0; j < n; j++)
- {
- if (a[i][j] < 0) {
- summ[i] += a[i][j];
- }
- }
- }
- for (int i = 0; i < n; i++)
- {
- cout << endl;
- cout << "Сумма элементов в " << i + 1 << "-ой строке " << summ[i];
- }
- cout << endl;
- for (int i = 0; i < n - 1; i++)
- {
- for (int k = i + 1; k < n; k++)
- {
- if (summ[i] > summ[k])
- {
- buf = summ[i];
- summ[i] = summ[k];
- summ[k] = buf;
- for (int j = 0; j < n; j++)
- {
- buf = a[i][j];
- a[i][j] = a[i][k];
- a[i][k] = buf;
- }
- }
- }
- }
- for (int i = 0; i < n; i++)
- {
- cout << endl;
- for (int j = 0; j < n; j++)
- {
- cout << a[i][j] << " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement