Question 6
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
for (int x = 9; x <= 15; x++) {
if (x % 15 == 0)
printf("FizzBuzz ");
else if (x % 3 == 0)
printf("Fizz ");
else if (x % 5 == 0)
printf("Buzz ");
else
printf("%d ", x);
}
printf("\n");
return 0;
}
- A Fizz Buzz 11 Fizz 13 14 FizzBuzz Correct
- B Fizz Buzz 11 Fizz 13 14 Fizz
- C 9 10 11 12 13 14 15
- D Fizz Buzz 11 Fizz 13 14 Buzz
Correct Answer: Option A
The ladder stops at the first true test, so the most specific check (divisible by 15) must come first; otherwise 15 would print just "Fizz".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!