- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang Program to Check Whether a Given Year is a Leap Year
Steps
- Take the value of the year as input.
- Using an if-statement, check whether the year is a leap year or not
- Print the final result.
Enter the year to be checked: 2016 The year is a leap year! | Enter the year to be checked: 2005 The year isn't a leap year! |
Explanation
- User must first enter the year to be checked.
- The if statement checks if the year is a multiple of 4 but isn't a multiple of 100 or if it is a multiple of 400 (not every year that is a multiple of 4 is a leap year).
- Then, the result is printed.
Example
package main import "fmt" func main() { var year int fmt.Print("Enter the year to be checked:") fmt.Scanf("%d", &year) if year%4==0 && year%100!=0 || year%400==0{ fmt.Println("The year is a leap year!") }else{ fmt.Println("The year isn't a leap year!") } }
Output
Enter the year to be checked:2016 The year is a leap year!
- Related Articles
- JavaScript program to check if a given year is leap year
- Program to check if a given year is leap year in C
- Check if a given year is leap year in PL/SQL
- PHP program to check if a year is leap year or not
- Python Pandas - Check whether the year is a leap year from the Period object
- C++ Program to Check Leap Year
- Java Program to Check Leap Year
- How to check whether a year or a vector of years is leap year or not in R?
- How to detect if a given year is a Leap year in Oracle?
- Java program to find if the given number is a leap year?
- How to Check Leap Year using Python?
- How to find a leap year using C language?
- Python Pandas - Indicate whether the date in DateTimeIndex belongs to a leap year or not
- What do you mean by a leap year?
- Golang Program to extract the last two digits from the given year

Advertisements