basics · beginner · ~15 min
Order if/else branches so the most specific case wins.
Return the FizzBuzz word for a number — the classic test of branch ordering.
Implement const char *fizzbuzz_word(int n) that returns:
"FizzBuzz" if n is divisible by both 3 and 5 (i.e. by 15),"Fizz" if divisible by 3 only,"Buzz" if divisible by 5 only,"".Check divisibility by 15 first, or the single-factor cases would shadow it. No main — the grader calls it.
A single int n.
Returns one of "FizzBuzz", "Fizz", "Buzz", or "".
fizzbuzz_word(15) -> "FizzBuzz"
fizzbuzz_word(9) -> "Fizz"
fizzbuzz_word(10) -> "Buzz"
fizzbuzz_word(7) -> ""
"FizzBuzz", not just "Fizz".A single int n.
"FizzBuzz", "Fizz", "Buzz", or "".
Check divisibility by 15 before 3 and 5.
const char *fizzbuzz_word(int n) {
/* TODO */
return "";
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.