rewrite to ternary (x≥y) max=x¡ else max = y¡
Answers
Answered by
1
Given:
if(x >= y)
max = x;
else
max = y;
Rewritten in ternary operator:
max = (x >= y) ? x : y;
Ternary operator:
Expression1 ? Expression2 : Expression3
condition ? value if true : value if false
Questions for practice:
Question 1: Rewrite to ternary operator
if(x % 2 == 0)
rem = 0;
else
rem = 1;
Question 2: Rewrite to ternary operator
if(a > b)
cout<<"a is large";
else
cout<<"b is large";
Similar questions