Created
July 5, 2013 20:24
-
-
Save emberlzhang/5937010 to your computer and use it in GitHub Desktop.
FizzBuzz in Ruby: Write a program that prints out the numbers 1 to 100 (inclusive). If the number is divisible by 3, print Fizz instead of the number. If it's divisible by 5, print Buzz. If it's divisible by both 3 and 5, print FizzBuzz.
This file contains 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
numbers = Array(1..100) | |
numbers.each do |num| | |
if num % 15 == 0 | |
puts "FizzBuzz" | |
elsif num % 5 == 0 | |
puts "Buzz" | |
elsif num % 3 == 0 | |
puts "Fizz" | |
else | |
puts num | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment