Last active
August 24, 2016 19:32
-
-
Save suryart/6561608 to your computer and use it in GitHub Desktop.
Write a program which prints the numbers from 1 to N, each on a new line. But for multiples of three print “Fizz” instead of the number 3 and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”. Read in the input number from STDIN.Solution below is in ruby.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.upto(STDIN.gets.to_i) do |num| | |
break if num > 10**7 # num should be less than 10^7 | |
output = nil | |
output = output.to_s + 'Fizz' if num % 3 == 0 | |
output = output.to_s + 'Buzz' if num % 5 == 0 | |
puts output || num | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment