Advertisement
Polnochniy

Untitled

Jan 22nd, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. using namespace std;
  4. const int N = 3;
  5. const int P = 4;
  6. int summ(int number)
  7. {
  8. int F = number;
  9. int sum = 0;
  10. while (F > 0)
  11. {
  12. sum += F % 10;
  13. F = F / 10;
  14. }
  15. return sum;
  16. }
  17. void cinn(int a[N][P], int N, int P)
  18. {
  19. cout << "Введите элементы массива" << endl;
  20. for (int i = 0; i < N; i++)
  21. {
  22. for (int j = 0; j < P; j++)
  23. {
  24. cin >> a[i][j];
  25. }
  26. cout << endl;
  27. }
  28. }
  29. void coutt(int a[N][P], int N, int P)
  30. {
  31. cout << "Вывод элементов " << endl;
  32. for (int i = 0; i < N; i++)
  33. {
  34. for (int j = 0; j < P; j++)
  35. {
  36. cout << a[i][j] << " ";
  37. }
  38. cout << endl;
  39. }
  40. cout << endl;
  41. }
  42. void summ_numbers(int* a, int N )
  43. {
  44. cout << "Сумма цифр для каждого элемента стобца" << endl;
  45. for (int j = 0; j < N; j++)
  46. {
  47. cout << summ(a[j]) << " " << endl;
  48. }
  49. }
  50. int main()
  51. {
  52. int a[N][P];
  53. int k[P];
  54. setlocale(LC_ALL, "Rus");
  55. srand(time(NULL));
  56. cout <<" Сортировать стобцы по сумм цифр " <<endl;
  57. cinn(a, N, P);
  58. coutt(a, N, P);
  59. summ_numbers(*a, N);
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement