Challenge 14 - Leap Years

👋 Welcome Gophers, in this challenge, you are tasked with implementing a function that returns whether or not a year is in fact a leap year.

View Solution
package main

import "fmt"

func CheckLeapYear(year int) bool {
 // If a year is multiple of 400,  
  // then it is a leap year 
  if year % 400 == 0 {
  	return true; 
  }

  // Else If a year is muliplt of 100, 
  // then it is not a leap year 
  if year % 100 == 0 {
  	return false; 
  }

  // Else If a year is muliplt of 4, 
  // then it is a leap year 
  if year % 4 == 0 {
  	return true; 
  }
  return false; 
}

func main() {
  fmt.Println("Check Leap Year")

  year := 2020
  fmt.Println(CheckLeapYear(year))
}

Further Reading:

If you enjoyed this challenge, you may also enjoy some of the other challenges on this site:


Other Challenges