Polnochniy

Untitled

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