Debug program

Report a typo

Philip J. Fry loves to celebrate February 29th. But, after traveling into the future, he realized he had missed many holidays.

He asked his friend Bender to calculate how many times he needs to celebrate a leap year instead of missed ones from 1999 to 2999. Bender wrote a simple algorithm, but Professor Farnsworth laughed because it didn't work! Help Fry calculate how many days he really missed.

Remember that:

  • a year whose number is a multiple of 400 - a leap year (for example, 2400, 2800)

  • other years, the number of which is a multiple of 100 - non-leap years (2500, 2900, etc.)

  • other years, the number of which is a multiple of 4 - are leap years (for example, 2996, 2304, etc.)

Sample Input 1:

Sample Output 1:

243 leap years from 1999 to 2999
Write a program in Go
package main

import "fmt"

func main() {
freezing := 1999
defrosting := 2999

leapYear := 0
for year := defrosting; year <= freezing; year++ {
if isLeap(year) {
leapYear++
} else {
leapYear--
}
}

// Please, don't modify this print statement below:
fmt.Printf("%d leap years from %d to %d", leapYear, freezing, defrosting)
}

func isLeap(year int) bool {
if year%400 == 0 {
return true
} else if year%4 == 0 {
return true
} else if year%100 == 0 {
return false
}
return false
}
___

Create a free account to access the full topic