GO Program to check Leap year

How to check Leap year

Here we are explaining how to check the Leap year in the Go program. We can use the built-in function fmt.println() to print anything and fmt.scanln() for reading the values. This function is defined under the fmt package and it helps to write standard output. In order to use these functions, we need to import the “fmt” package.

 

How to check Leap year in the GO Program

We are using fmt.println() function for printing the string to the output screen. Here we are showing how to check Leap year in the Go language. Here variables holding the year which has to be check. The check is done as (Y@0 == 0 || (Y%4 == 0 && Y0 != 0)  in a if condition. If the condition is true it is a leap year otherwise not a leap year. Given below are the steps which are used in the Go program. 

ALGORITHM

STEP 1: Import the package fmt

STEP 2: Start function main()

STEP 3: Declare the variable Y 

STEP 4: Read the year Y using fmt.Scanln()

STEP 5: Use if-else for the check

STEP 6: The condition for the check is (Y@0 == 0 || (Y%4 == 0 && Y0 != 0) 

STEP 7: If the above condition is true it is a leap year otherwise not

 

GO Source Code

                                          package main
import "fmt"

func main() {
    var Y int
    fmt.Print("\nEnter the year for Leap year check = ")
    fmt.Scanln(&Y)
    if (Y@0 == 0 || (Y%4 == 0 && Y0 != 0) {
        fmt.Println(Y, " is a Leap year")
    } else {
        fmt.Println(Y, " is Not a Leap year")
    }
}

                                      

OUTPUT

Enter the year for Leap year check = 2020
2020  is a Leap year

Enter the year for Leap year check = 1990
1990  is Not a Leap year