Q:

Write a Ruby program to test whether a year is leap year or not

0

Write a Ruby program to test whether a year is leap year or not.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

year = [2012, 1500, 1600, 2020]
year.each do |y|
  if y % 400 == 0
  	 puts y.to_s + ' is leap year'
    elsif y % 4==0 && y % 100 != 0 
      puts y.to_s + ' is leap year'
  else  puts y.to_s + ' is not leap year'
  end
end
 Output:
2012 is leap year
1500 is not leap year
1600 is leap year
2020 is leap year

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now