A year is leap year if the following conditions are satisfied:
- Year is multiple of 400.
- Year is multiple of 4 and not multiple of 100.

Following is pseudo-code
if year is divisible by 400 then is_leap_year else if year is divisible by 100 then not_leap_year else if year is divisible by 4 then is_leap_year else not_leap_year
C++
// C++ program to check if a given // year is leap year or not #include <bits/stdc++.h>using namespace std; bool checkYear(int year) { // If a year is multiple of 400, // then it is a leap year if (year % 400 == 0) return true; // Else If a year is muliplt of 100, // then it is not a leap year if (year % 100 == 0) return false; // Else If a year is muliplt of 4, // then it is a leap year if (year % 4 == 0) return true; return false; } // Driver code int main() { int year = 2000; checkYear(year) ? cout << "Leap Year": cout << "Not a Leap Year"; return 0; } // This is code is contributed // by rathbhupendra |
chevron_right
filter_none
C
// C program to check if a given // year is leap year or not#include <stdio.h>#include <stdbool.h>bool checkYear(int year){ // If a year is multiple of 400, // then it is a leap year if (year % 400 == 0) return true; // Else If a year is muliplt of 100, // then it is not a leap year if (year % 100 == 0) return false; // Else If a year is muliplt of 4, // then it is a leap year if (year % 4 == 0) return true; return false;}// driver codeint main(){ int year = 2000; checkYear(year)? printf("Leap Year"): printf("Not a Leap Year"); return 0;} |
chevron_right
filter_none
Java
// Java program to check// for a leap year class Test{ static boolean checkYear(int year) { // If a year is multiple of 400, // then it is a leap year if (year % 400 == 0) return true; // Else If a year is muliplt of 100, // then it is not a leap year if (year % 100 == 0) return false; // Else If a year is muliplt of 4, // then it is a leap year if (year % 4 == 0) return true; return false; } // Driver method public static void main(String[] args) { int year = 2000; System.out.println( checkYear(2000)? "Leap Year" : "Not a Leap Year" ); }} |
chevron_right
filter_none
Python3
# Python program to check leap year or notdef checkYear(year): if (year % 4) == 0: if (year % 100) == 0: if (year % 400) == 0: return True else: return False else: return True else: return False# Driver Code year = 2000if(checkYear(year)): print("Leap Year")else: print("Not a Leap Year") # This code is contributed by Chinmoy Lenka |
chevron_right
filter_none
C#
// C# program to check// for a leap yearusing System;class GFG{ static bool checkYear(int year) { // If a year is multiple of 400, // then it is a leap year if (year % 400 == 0) return true; // Else If a year is muliplt of 100, // then it is not a leap year if (year % 100 == 0) return false; // Else If a year is muliplt of 4, // then it is a leap year if (year % 4 == 0) return true; return false; } // Driver method public static void Main() { int year = 2000; Console.Write( checkYear(year)? "Leap Year" : "Not a Leap Year" ); }}// This code is contributed by Sam007 |
chevron_right
filter_none
PHP
<?php// PHP code to check if a given// year is leap yearfunction checkYear($year) { // If a year is multiple of 400, // then it is a leap year if ($year % 400 == 0) print("Leap Year"); // Else If a year is muliplt of 100, // then it is not a leap year else if ($year % 100 == 0) print("Not a Leap Year"); // Else If a year is multiple of 4, // then it is a leap year else if ($year % 4 == 0) print("Leap Year"); else print("Not a Leap Year"); } // Driver code $year = 2000; checkYear($year); // This code is contributed by ash264?> |
chevron_right
filter_none
Output:
Leap Year
How to write the above code in one line?
C++
// One line C program to check if a // given year is leap year or not#include <bits/stdc++.h>using namespace std;bool checkYear(int year){ // Return true if year is a multiple // 0f 4 and not multiple of 100. // OR year is multiple of 400. return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));}// Driver codeint main(){ int year = 2000; checkYear(year)? cout << "Leap Year": cout << "Not a Leap Year"; return 0;}// This code is contributed by Akanksha Rai |
chevron_right
filter_none
C
// One line C program to check if a // given year is leap year or not#include <stdio.h>#include <stdbool.h>bool checkYear(int year){// Return true if year is a multiple// 0f 4 and not multiple of 100.// OR year is multiple of 400.return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));}// driver codeint main(){ int year = 2000; checkYear(year)? printf("Leap Year"): printf("Not a Leap Year"); return 0;} |
chevron_right
filter_none
Java
// Java program to check// for a leap year class Test{ static boolean checkYear(int year) { // Return true if year is a multiple // of 4 and not multiple of 100. // OR year is multiple of 400. return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); } // Driver method public static void main(String[] args) { int year = 2000; System.out.println(checkYear(2000)? "Leap Year" : "Not a Leap Year" ); }} |
chevron_right
filter_none
Python3
# Python program to check leap year# or not in a single linedef checkYear(year): # Return true if year is a multiple # of 4 and not multiple of 100. # OR year is multiple of 400. return (((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0));# Driver Code year = 2000if(checkYear(year)): print("Leap Year")else: print("Not a Leap Year") # This code is contributed by Chinmoy Lenka |
chevron_right
filter_none
C#
// C# program to check// for a leap yearusing System;class GFG{ static bool checkYear(int year) { // Return true if year is a multiple // of 4 and not multiple of 100. // OR year is multiple of 400. return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); } // Driver method public static void Main() { int year = 2000; Console.Write( checkYear(year)? "Leap Year" : "Not a Leap Year" ); }}// This code is contributed by Sam007 |
chevron_right
filter_none
PHP
<?php// PHP code to check if a given// year is leap yearfunction checkYear($year) { // Return true if year is a multiple // 0f 4 and not multiple of 100. // OR year is multiple of 400. return ((($year % 4 == 0) && ($year % 100 != 0)) || ($year % 400 == 0));} // Driver code $year = 2000; checkYear($year)? print("Leap Year"): print("Not a Leap Year");// This code is contributed by ash264?> |
chevron_right
filter_none
Output:
Leap Year
Check Leap Year using Macros in C/C++
The program outputs 1 if year is leap and 0 if it’s not a leap year.
C++
// C++ implementation to check // if the year is a leap year // using macros#include <iostream>using namespace std;// Macro to check if a year // is a leap year#define ISLP(y) ((y % 400 == 0) ||\(y % 100 != 0) && (y % 4 == 0)) // Driver Codeint main(){ int year = 2020; cout << ISLP(year) << "\n"; return 0;} |
chevron_right
filter_none
Output
1
Short Solution in Python :
Python
def checkYear(year): # Return true if year is a multiple # of 4 and not multiple of 100. # OR year is multiple of 400. import calendar return(calendar.isleap(year)) # Driver Code year = 2000if (checkYear(year)): print("Leap Year") else: print("Not a Leap Year") # This code is contributed by Chin |
chevron_right
filter_none
Output
Leap Year
Recommended Posts:
- C program to check if a given year is leap year using Conditional operator
- C program to display month by month calendar for a given year
- Program to find century for a year
- Python program to calculate age in year
- Print calendar for a given year in C++
- How to calculate the Easter date for a given year using Gauss' Algorithm
- Find the next identical calendar year
- Why is programming important for first year or school students?
- Print the season name of the year based on the month number
- How to get Day, Month and Year from Date in Java
- Program to check if two given matrices are identical
- C Program to Check if a Given String is Palindrome
- Program to check whether the given number is Buzz Number or not
- Program to check if tank will overflow, underflow or filled in given time
- Python program to check if given string is vowel Palindrome
- C program to check whether a given number is even or odd
- Program to check if a date is valid or not
- Java program to check palindrome (using library methods)
- Python program to check if a string is palindrome or not
- Program to check for Peterson number

