Go language program to take a year as input and tells whether it's a leap year or not
Following program shows you how take a year as input and tells whether it's a leap year or not.
package main
import "fmt"
func main() {
var input int
fmt.Println("Enter a year:")
fmt.Scanf("%d", &input)
if (input % 4 == 0) {
if (input % 100 == 0) {
if (input % 400 == 0) {
fmt.Println(input , " its a leap year")
} else {
fmt.Println(input , " its not a leap year")
}
} else {
fmt.Println(input , " its a leap year")
}
} else {
fmt.Println(input , " its not a leap year")
}
}
Output:
Example1:
Enter a year:
2012
2012 its a leap year
Example2:
Enter a year:
2019
2019 its not a leap year