Last active
June 23, 2025 23:02
-
-
Save iMagesh/21d28e13acd1c12fc43c426e04a1c95e to your computer and use it in GitHub Desktop.
Write a program that prints out the numbers 1 to 100 (inclusive). If the number is divisible by 3, print Crackle instead of the number. If it's divisible by 5, print Pop instead of the number. If it's divisible by both 3 and 5, print CracklePop instead of the number. You can use any language.
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
def crackle_pop(first, last) | |
(first..last).each do |number| | |
if number % 15 == 0 | |
puts 'CracklePop' | |
elsif number % 3 == 0 | |
puts 'Crackle' | |
elsif number % 5 == 0 | |
puts 'Pop' | |
else | |
puts number | |
end | |
end | |
end | |
crackle_pop(1, 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment