UtiNii!
![]()
- Write a program that prints the numbers from 1 to 100.
- But for multiples of three print “Uti” instead of the number and for the multiples of five print “Nii!”.
- For numbers which are multiples of both three and five print “UtiNii!”
Solution in Ruby
1.upto(100) do |i|
if i % 5 == 0 and i % 3 == 0
puts "UtiNii!"
elsif i % 5 == 0
puts "Uti"
elsif i % 3 == 0
puts "Nii!"
else
puts i
end
end