Menu Close

Go – Program to check Leap year or not in go

Here, we will write a program to check Leap year or not. Given below, you can find algorithm and program.

Leap year is a year which should follow given below conditions:

  • If the year is evenly divisible by 4.
  • year should not be evenly divided by 100.
  • If the year is also evenly divisible by 400.

year : 2000

output: It is a leap year.

Code:

package main

import (

  "fmt"

)

func is_leap_year(year int) bool {

  if ((year % 4 == 0) || (year % 400 == 0)) {

    return true

  } else if(year % 100 == 0) {

      return false

  } else {

    return false

  }
}

func main() {

  fmt.Println(is_leap_year(2000))

  fmt.Println(is_leap_year(1980))

  fmt.Println(is_leap_year(2001))
}

Output:

true

true

false

To learn more about golang. Please follow given below link.

https://www.techieindoor.com/go-lang/

References:

https://golang.org/doc/
https://golang.org/pkg/

Posted in golang, golang program

Leave a Reply

Your email address will not be published.

Contact Us