Wednesday, June 28, 2006

LeapYear V2

And Neo said....'Hmmmm. Upgrades'.

Here is the version 2.0 of the program:

# LeapYearv2.rb - This program reads an year and tells whether it is a LeapYear or not.
# Author - Ashish Kulkarni (http://ashishkulkarni.blogspot.com)
# Date - 28-Jun-2006

GregorianCutoverYear = 1582

puts 'Please input the year for checking for Leap Year:'
STDOUT.flush
year = STDIN.gets.chomp.to_i

if (year >= GregorianCutoverYear && # Gregorian
((year.modulo(4) == 0) &&
((year.modulo(100) != 0) ||
(year.modulo(400) == 0)))) ||
(year < GregorianCutoverYear && # Julian
year.modulo(4) == 0)
puts 'It is a Leap Year'
else
puts 'It is not a Leap Year'
end


Output:

Please input the year for checking for Leap Year:
2000
It is a Leap Year

Please input the year for checking for Leap Year:
2002
It is not a Leap Year

Please input the year for checking for Leap Year:
2004
It is a Leap Year

Please input the year for checking for Leap Year:
2006
It is not a Leap Year

Please input the year for checking for Leap Year:
3000
It is not a Leap Year

0 Comments:

Post a Comment

<< Home