5. Use the conditional operator to assign the value of x to the variable y only if x is between 1 and 20. Leave y unchanged if x is not in that range.
(If 'between' means 'inclusive of 1 and 20')
y = (x>=1 && x<=20) ? x : y;
(If 'between' means 'exclusive of 1 and 20')
y = (x>1 && x<20) ? x : y;
No comments:
Post a Comment