Advertisement
Spocoman

03. Even or Odd

Sep 1st, 2023 (edited)
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int number;
  7.     cin >> number;
  8.  
  9.     if (number % 2 == 0) {
  10.         cout << "even" << endl;
  11.     }
  12.     else {
  13.         cout << "odd" << endl;
  14.     }
  15.  
  16.     return 0;
  17. }
  18.  
  19. Решение с тернарен оператор:
  20.  
  21. #include <iostream>
  22.  
  23. using namespace std;
  24.  
  25. int main() {
  26.     int number;
  27.     cin >> number;
  28.  
  29.     cout << (number % 2 == 0 ? "even" : "odd") << endl;
  30.    
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement