Check Leap Year

Check Leap Year

Medium C++ Control Flow 38 views
Explanation Complexity

Problem Statement

Check if given year is leap year or not.
Real Life: Like February having 29 days in some years.

Input Format

An integer year.

Output Format

Print

• Leap Year
OR

• Not a Leap Year

Example

2024
Leap Year

Constraints

• year > 0

Concept Explanation

A leap year decides whether February has 28 or 29 days.
Leap year rules are fixed and must be checked in order.

Step-by-Step Explanation

1.Take input year.

2.If year is divisible by 400:

• It is a Leap Year.

3.Else if year is divisible by 100:

• It is Not a Leap Year.

4.Else if year is divisible by 4:

• It is a Leap Year.

5.Else:

• It is Not a Leap Year.

Concept Explanation

A leap year decides whether February has 28 or 29 days.
Leap year rules are fixed and must be checked in order.

Step-by-Step Explanation

1.Take input year.

2.If year is divisible by 400:

• It is a Leap Year.

3.Else if year is divisible by 100:

• It is Not a Leap Year.

4.Else if year is divisible by 4:

• It is a Leap Year.

5.Else:

• It is Not a Leap Year.

Input / Output Format

Input Format
An integer year.
Output Format
Print

• Leap Year
OR

• Not a Leap Year
Constraints
• year > 0

Examples

Input:
2024
Output:
Leap Year

Example Solution (Public)

C++
void control_q6_leap_year() {
    int year = 2024;
    
    bool isLeap = false;
    
    if(year % 400 == 0) {
        isLeap = true;
    } else if(year % 100 == 0) {
        isLeap = false;
    } else if(year % 4 == 0) {
        isLeap = true;
    }
    
    if(isLeap) {
        cout << year << " is a Leap Year" << endl;
    } else {
        cout << year << " is NOT a Leap Year" << endl;
    }
}

Official Solution Code

void control_q6_leap_year() {
    int year = 2024;
    
    bool isLeap = false;
    
    if(year % 400 == 0) {
        isLeap = true;
    } else if(year % 100 == 0) {
        isLeap = false;
    } else if(year % 4 == 0) {
        isLeap = true;
    }
    
    if(isLeap) {
        cout << year << " is a Leap Year" << endl;
    } else {
        cout << year << " is NOT a Leap Year" << endl;
    }
}
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.