Leap Year | Practice | GeeksforGeeks

For an input year N, find whether the year is a leap or not. 
 
Example 1:
Input:
N = 4
Output:
1
Explanation:
4 is not divisible by 100
and is divisible by 4 so its
a leap year
Example 2:
Input:
N = 2021
Output:
0
Explanation:
2021 is not divisible by 100
and is also not divisible by 4
so its not a leap year

Your Task:
You don't need to read input or print anything. Your task is to complete the function isLeap() which takes an integer N as input parameter and returns 1 is N is a leap year and 0 otherwise.
 
Expected Time Complexity: O(1)
Expected Space Complexity: O(1)

Constraints:
1<=N<=9999
+1
dasilashubham396 days ago
//code here
if(N%4!=0){
           return 0;
       }
       else{
           if(N%100!=0){
               return 1;
           }
           else{
               if(N%400==0){
                   return 1;
               }
               else{
                   return 0;
               }
           }
       }
0
dasilashubham39
This comment was deleted.
+1
kumarr32033 weeks ago
//c++ solution
 
   int isLeap(int n){       //code here              if(n%4==0)       {           if(n%100==0)           {               if(n%400==0)               {                   return 1;               }               else               {                   return 0;               }           }           else           {               return 1;           }       }       else       {           return 0;       }   }}; 
0
singhanurudh061 month ago
int isLeap(int N){if ((N%4==0 && N%100!=0) || N%400==0)   return 1;else   return 0;}
0
haroonhnpwd11 month ago
{
    // If a year is multiple of 400,
    // then it is a leap year
    if (year % 400 == 0)
        return true;
    // Else If a year is multiple of 100,
    // then it is not a leap year
    if (year % 100 == 0)
        return false;
    // Else If a year is multiple 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
 
0
mco0lPremium1 month ago
return (N%4 == 0) && (N%100 != 0) || (N%400 == 0);
0
itmithu1432 months ago
if((N%4==0 && N%100!=0)|| N%400==0)       return true;       else       return false;
 
+1
upadhyayshikhar065 months ago
int isLeap(int N)
{      return(((N % 4 == 0) &&(N % 100!= 0))||(N % 400 == 0));          }
0
badgujarsachin837 months ago
int isLeap(int N){
        //code here
        if(N>=400 && N%400==0){
            return 1;
        }
        if(N%4==0 && N%100!=0){
            return 1;
            
        }
        return 0;
    }
-1
xasha1227999 months ago
/*
1. Leap Year:
A year is a leap year if the following conditions are satisfied:
The year is multiple of 400.
The year is multiple of 4 and not multiple of 100.
*/
 
#include <bits/stdc++.h>
using namespace std;
 
// Function Declarations
 
// Driver Code
int main()
{
int N;
cin >> N;
isLeap(N);
 
return 0;
} // Main Ends
 
Function Definition
 
int isLeap(int N)
{
// Basically we, need to check for 3 conditions: Nested Loops is what is required to evaluate either a year is leap or not
 
if (N % 4 == 0)
{ // come here if year passed is divisible by 4
if (N % 100 == 0)
{ // come here if year passed is divisible by 100
if (N % 400 == 0)
{ // come here if year passed is divisible by 400
cout << "leap year";
}
else
{ // come here if year passed is divisible by 100 but not by 400
cout << "not leap year";
}
}
else
{ // come here if year passed is divisible by 4 and not divisible by 100
cout << "leap year";
}
}
else
{ // come here if year passed is not divisible by 4
cout << "not leap year";
}
}
 
OR
 
int isLeap(int N)
{
// 4 and 100 walli condition for normal years and 400 waali condition is for century year's
if ((N % 4 == 0 and N % 100 != 0) or (N % 400 == 0))
{
return 1;
}
else
{
return 0;
}
}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested 
                                    against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code.
                                    On submission, your code is tested against multiple test cases consisting of all
                                        possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as
                                        the final solution code.
You can view the solutions submitted by other users from the submission tab.
Make sure you are not using ad-blockers.
Disable browser extensions.
We recommend using latest version of your browser for best experience.
Avoid using static/global variables in coding problems as your code is tested 
                                against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases in coding problems does not guarantee the 
                                correctness of code. On submission, your code is tested against multiple test cases
                                    consisting of all possible corner cases and stress constraints.