Ruby program to check leap year

bookmark

=begin
  Ruby program to check whether 
  the year is leap year or not.    
=end

puts "Enter the year you want to check"
yr = gets.chomp.to_i

if yr % 400 == 0
    puts "#{yr} is a leap year"
elsif yr % 4 == 0 && yr % 100 !=0
    puts "#{yr} is a leap year"
else
    puts "#{yr} is not a leap year"
end

 


Output:

RUN 1:
Enter the year you want to check
 2020
2020 is a leap year

RUN 2:
Enter the year you want to check
 1900
1900 is not a leap year

RUN 3:
Enter the year you want to check
 2200
2200 is not a leap year

RUN 4:
Enter the year you want to check
 2204
2204 is a leap year