Write a Ruby script program to determine if an input year is

Write a Ruby script program to determine if an input year is a leap year or not. Here is an example run: Enter Year: 1999 Year entered is NOT a leap year. Do you want to test check another year? Y Enter Year: 2016 Year entered is a leap year. Do you want to test check another year? N Thanks.

Solution

def is_leap(year)

if year % 400 == 0

        true

    elsif year % 100 == 0

        false

    elsif year % 4 == 0

        true

    else

        false

    end

end

years = [1900, 2000, 2014, 2016]

years.each do |year|

    if is_leap(year)

        puts \"#{year} is a leap year.\"

    else

        puts \"#{year} is not a leap year.\"

    end

end

 Write a Ruby script program to determine if an input year is a leap year or not. Here is an example run: Enter Year: 1999 Year entered is NOT a leap year. Do y

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site