Fizz Buzz
View as PDFThe iconic coding interview question to filter out bad programmers. Fizz Buzz. It's deceptively simple, yet out of
interviewees cannot solve the problem. The task is simple: Print out a list of numbers from
to
, but replace multiples of
with
fizz, multiples of with
buzz and multiples of both with fizzbuzz. Can you pass the interview?
Input Specification
There will be one line of input containing one integer, , the number to stop at.
Output Specification
Output the numbers from to
(inclusive), replacing multiples of
with
fizz, multiples of 5 with buzz and multiples of both with fizzbuzz.
Please note that endl for C++ users will be too slow. Use \n or printf instead.
Sample Input
20
Sample Output
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19
buzz
Comments