-->

    Social Items

Go Program To Check Leap Year

Go Program To Check Leap Year - in this post, we will learn how to create a leap year check program in the Go programming language. Leap year is the year where the number of days is the most that occur every four years. The difference in leap year with the normal year is every February has a date up to 29.

Go Program To Check Leap Year


Source Code :


package main

import "fmt"

func main() {
  var year int

  fmt.Print("Enter a year: ")
  fmt.Scanln(&year)

  if year%400 == 0 {
    fmt.Println(year, "is a leap year")
  } else if year%100 == 0 {
    fmt.Println(year, "is not a leap year")
  } else if year%4 == 0 {
    fmt.Println(year, "is a leap year")
  } else {
    fmt.Println(year, "is not a leap year")
  }
}

Save the source code with the name of leapyear.go, but adjust wrote with a file name that chills and don't forget the extension should .go

Compile & Run :

Here's how to compile source code manually:

$ go build leapyear.go
$ ./leapyear
You can run without having to compile it:

$ go run leapyear.go

The Output of Program :

Picture of the result check leap year
Picture of the result check leap year

Go Program To Check Leap Year (Golang)

Go Program To Check Leap Year

Go Program To Check Leap Year - in this post, we will learn how to create a leap year check program in the Go programming language. Leap year is the year where the number of days is the most that occur every four years. The difference in leap year with the normal year is every February has a date up to 29.

Go Program To Check Leap Year


Source Code :


package main

import "fmt"

func main() {
  var year int

  fmt.Print("Enter a year: ")
  fmt.Scanln(&year)

  if year%400 == 0 {
    fmt.Println(year, "is a leap year")
  } else if year%100 == 0 {
    fmt.Println(year, "is not a leap year")
  } else if year%4 == 0 {
    fmt.Println(year, "is a leap year")
  } else {
    fmt.Println(year, "is not a leap year")
  }
}

Save the source code with the name of leapyear.go, but adjust wrote with a file name that chills and don't forget the extension should .go

Compile & Run :

Here's how to compile source code manually:

$ go build leapyear.go
$ ./leapyear
You can run without having to compile it:

$ go run leapyear.go

The Output of Program :

Picture of the result check leap year
Picture of the result check leap year

Subscribe Our Newsletter