Advertisement
Derga

Untitled

Feb 27th, 2023
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. /*
  2. Задание 2. Мой возраст
  3. */
  4.  
  5. #include <iostream>
  6. #include <locale>
  7.  
  8. using namespace std;
  9.  
  10. string getRightWord(int age) {
  11.     if (5 <= age && age <= 20) {
  12.         return "лет";
  13.     }
  14.  
  15.     int last_age_digit = age % 10;
  16.     if (last_age_digit == 1) {
  17.         return "год";
  18.     } else if (2 <= last_age_digit && last_age_digit <= 4) {
  19.         return "года";
  20.     } else {
  21.         return "лет";
  22.     }
  23. }
  24.  
  25. int main() {
  26.     setlocale(LC_ALL, "Russian");
  27.  
  28.     int age;
  29.     cin >> age;
  30.    
  31.     cout << "Мне " << age << " " << getRightWord(age);
  32.    
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement