Advertisement
hurmawe

8.6

May 19th, 2022
802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. bool odd_even(int number)
  6. {
  7.     int sum = 0;
  8.     while (number != 0)
  9.     {
  10.         sum += number % 10;
  11.         number /= 10;
  12.     }
  13.     return sum % 2;
  14. }
  15.  
  16. int main()
  17. {
  18. int number = 0;
  19.     cout << "Задание 2" << endl << "Введите число " << endl;
  20.     cin >> number;
  21.     if (odd_even(number))
  22.         cout << "Сумма цифр нечетная" << endl;
  23.     else
  24.         cout << "Сумма цифр четная" << endl;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement