Advertisement
Spocoman

06. Number in Range

Sep 4th, 2023 (edited)
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 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 >= -100 && number <= 100 && number != 0) {
  10.         cout << "Yes" << endl;
  11.     }
  12.     else {
  13.         cout << "No" << 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 >= -100 && number <= 100 && number != 0 ? "Yes" :"No") << endl;
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement