Advertisement
avr39ripe

BV012ternaryBasics

Feb 23rd, 2021
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     int a{ 42 };
  6.     int b{ 10 };
  7.     int c{ 15 };
  8.     //std::cout << "Enter two numbers to find maximum from\n";
  9.  
  10.     //std::cin >> a;
  11.     //std::cin >> b;
  12.  
  13.     int res{ 0 };
  14.  
  15.    
  16.     //if ( a > b )
  17.     //{
  18.     //    res = a;
  19.     //}
  20.     //if ( b > a)
  21.     //{
  22.     //    res = b;
  23.     //}
  24.  
  25.     //if (a < b )
  26.     //{
  27.     //    res = b;
  28.     //}
  29.     //else
  30.     //{
  31.     //    res = a;
  32.     //}
  33.  
  34.     //(a > b) ? (res = a) : (res = b);
  35.    // res =  ((a > b) ? (a) : (b));
  36.  
  37.     //res = a > b ? a > c ? a : c : b > c ? b : c;
  38.     res = a > b ? a : b;
  39.     res = res > c ? res : c;
  40.  
  41.  
  42.     //((conditionalExpr) ? (exprIfTrue) : (exprIfFalse));
  43.  
  44.     std::cout << "res = " << res << '\n';
  45.  
  46.     return 0;
  47. }
  48.  
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement