Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- const int N = 3;
- const int P = 4;
- int sum( int* a, int n)
- {
- int sum = 0;
- for (int i = 0; i < n; i++)
- {
- sum += a[i];
- }
- return sum;
- }
- int main()
- {
- int a[N][P];
- setlocale(LC_ALL, "Rus");
- srand(time(NULL));
- cout << "Сортировать строк по убыванию их сумм по строкам" << endl;
- cout << "Вывод элементов" << endl;
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < P; j++)
- {
- a[i][j] = rand() % 109 + (-37);
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- for (int i = 0; i < N-1; i++)
- {
- for (int j =i+1; j<N ; j++)
- {
- if (sum(a[i],N) < sum(a[j],P)) // вот тут .
- {
- swap(a[i], a[j]);
- }
- }
- }
- cout << "Результат " << endl;
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < P; j++)
- cout << a[i][j] << " ";
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment