Check Leap Year
C++
Medium
3 views
Problem Description
Check if given year is leap year or not.
Real Life: Like February having 29 days in some years.
Step-by-Step Logic:
1. Take year as input
2. Leap year if divisible by 4
3. But NOT leap if divisible by 100
4. BUT leap if divisible by 400
5. Print result
Official Solution
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;
}
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!