Advertisement
Spocoman

02. Greater Number

Sep 1st, 2023 (edited)
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int firstNumber, secondNumber;
  7.     cin >> firstNumber >> secondNumber;
  8.  
  9.     if (firstNumber > secondNumber) {
  10.         cout << firstNumber << endl;
  11.     }
  12.     else {
  13.         cout << secondNumber << endl;
  14.     }
  15.     return 0;
  16. }
  17.  
  18. Решение с тернарен оператор:
  19.  
  20. #include <iostream>
  21.  
  22. using namespace std;
  23.  
  24. int main() {
  25.     int firstNumber, secondNumber;
  26.     cin >> firstNumber >> secondNumber;
  27.  
  28.     cout << (firstNumber > secondNumber ? firstNumber : secondNumber) << endl;
  29.    
  30.     return 0;
  31. }
  32.  
  33. Решение с max():
  34.  
  35. #include <iostream>
  36.  
  37. using namespace std;
  38.  
  39. int main() {
  40.  
  41.     int firstNumber, secondNumber;
  42.     cin >> firstNumber >> secondNumber;
  43.  
  44.     cout << max(firstNumber, secondNumber) << endl;
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement