In this article, you’ll learn how to check whether the given year is a leap year or not using C++, Python, JavaScript, and C.
Problem Statement
You’re given a year. You need to check whether the given year is a leap year or not.
Example 1: Let year = 2021.
2021 is not a leap year.
Thus, the output is “2021 is not a leap year”.
Example 2: Let year = 1980.
1980 is a leap year.
Thus, the output is “1980 is a leap year”.
Condition for a Year to Be a Leap Year
A year is a leap year if any or both of the following conditions are satisfied:
The year is a multiple of 400. The year is a multiple of 4 and not a multiple of 100.
C++ Program to Check Whether a Year Is a Leap Year or Not
Below is the C++ program to check whether a given year is a leap year or not:
Output:
Python Program to Check Whether a Year Is a Leap Year or Not
Below is the Python program to check whether a given year is a leap year or not:
JavaScript Program to Check Whether a Year Is a Leap Year or Not
Below is the JavaScript program to check whether a given year is a leap year or not:
Output:
C Program to Check Whether a Year Is a Leap Year or Not
Below is the C program to check whether a given year is a leap year or not:
Output:
Make Programming Easier Using Coding Apps
If you’re looking out for a fun way to learn to code, you can use some apps like Enki, Grasshopper, SoloLearn, Codeacademy Go, Hopscotch, Encode, etc. These apps provide great environments for learning to code in a fun and interactive way. They’ll help you stay on top of your game by coding wherever you are.