C/C++ Arena

Step 5 of 6

The ternary operator

condition ? a : b is an expression that evaluates to a if the condition is true and b otherwise. It's handy for small choices:

int best = (x > y) ? x : y;
printf("%s\n", n == 1 ? "kill" : "kills");

Your turn: read an int n and print n kill or n kills with the correct plural (1 is singular, everything else plural).

Previous: switch Next: Challenge: leap years