basics · beginner · ~15 min

FizzBuzz word

Order if/else branches so the most specific case wins.

Challenge

Return the FizzBuzz word for a number — the classic test of branch ordering.

Task

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,
  • otherwise the empty string "".

Check divisibility by 15 first, or the single-factor cases would shadow it. No main — the grader calls it.

Input

A single int n.

Output

Returns one of "FizzBuzz", "Fizz", "Buzz", or "".

Example

fizzbuzz_word(15)   ->   "FizzBuzz"
fizzbuzz_word(9)    ->   "Fizz"
fizzbuzz_word(10)   ->   "Buzz"
fizzbuzz_word(7)    ->   ""

Edge cases

  • A number divisible by both 3 and 5 must return "FizzBuzz", not just "Fizz".

Rules

  • Test the combined (divisible-by-15) case before the single-factor cases.

Input format

A single int n.

Output format

"FizzBuzz", "Fizz", "Buzz", or "".

Constraints

Check divisibility by 15 before 3 and 5.

Starter code

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.