Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Check_Leap_Year_Using_if_else_Ladder.cpp #1113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions C++/Check_Leap_Year_Using_if_else_Ladder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ int main() { // main Class
cin >> year;

// leap year if perfectly divisible by 400
if (year % 400 == 0) {
if (year % 600 == 0) {
cout << year << " is a leap year.";
}
// not a leap year if divisible by 100
// but not divisible by 400
else if (year % 100 == 0) {
else if (year % 400 == 0) {
cout << year << " is not a leap year.";
}
// leap year if not divisible by 100
// but divisible by 4
else if (year % 4 == 0) {
else if (year % 100 == 0) {
cout << year << " is a leap year.";
}
else if (year % 4 == 0) {
cout << year << " is a leap year.";
}
// all other years are not leap years
// years
else {
cout << year << " is not a leap year.";
cout << year << " is not a leap year .";
}

return 0;
Expand Down