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 summ(int number)
- {
- int sum = 0;
- int F = number;
- while (F > 0)
- {
- sum += F % 10;
- F = F / 10;
- }
- return sum;
- }
- void cinn(int a[N][P], int N, int P)
- {
- cout << "Введите элементы массива" << endl;
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < P; j++)
- {
- cin >> a[i][j];
- }
- cout << endl;
- }
- }
- void coutt(int a[N][P], int N, int P)
- {
- cout << "Вывод элементов " << endl;
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < P; j++)
- {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- }
- void summ_numbers(int a[N][P], int N, int P)
- {
- cout << "Сумма цифр для cтолбцов элементов " << endl;
- for (int j = 0; j < P; j++)
- {
- for (int i = 0; i < N; i++)
- {
- cout << summ(a[i][j]) << " " << endl;
- }
- cout << endl;
- }
- }
- int sum_numbers_all_P(int a[N][P], int index_col, int Num_rows)
- {
- int summm = 0;
- for (int index_row = 0; index_row < Num_rows; index_row++)
- {
- summm = summm + summ(a[index_row][index_col]);
- }
- return summm;
- }
- void sort(int a[N][P], int N, int P)
- {
- for (int indexCol = 0; indexCol < P; indexCol++)
- {
- for (int indexCol2 = indexCol + 1; indexCol2 < P; indexCol2++)
- {
- for (int indexCol2 = indexCol + 1; indexCol2 < P; indexCol2++)
- {
- if (sum_numbers_all_P(a, indexCol, N) < sum_numbers_all_P(a, indexCol2, N))
- {
- for (int k = 0; k < N; k++)
- {
- swap(a[k][indexCol], a[k][indexCol2]);
- }
- }
- }
- }
- }
- }
- void rez(int a[N][P], int N, int P)
- {
- cout << "Результат " << endl;
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < P; j++)
- {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- }
- int main()
- {
- int a[N][P];
- setlocale(LC_ALL, "Rus");
- srand(time(NULL));
- cout << " Сортировать элементы стобцов по сумм цифр " << endl;
- cinn(a, N, P);
- coutt(a, N, P);
- summ_numbers(a, N, P);
- cout << "Общая сумма цифр для каждого столбца " << endl;
- for (int indexCol = 0; indexCol < P; indexCol++)
- {
- cout << sum_numbers_all_P(a, indexCol, N) << " " << endl;
- }
- sort(a, N, P);
- rez(a, N, P);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment