Created
February 25, 2025 07:09
-
-
Save thearyanahmed/81e76cbbb8a9e02bdb98cf3b56c56eeb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
int year, nearestLeap; | |
printf("Enter a year: "); | |
scanf("%d", &year); | |
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { | |
printf("%d is a leap year.\n", year); | |
} else { | |
// Find the nearest leap year | |
if ((year + 1) % 4 == 0 && ((year + 1) % 100 != 0 || (year + 1) % 400 == 0)) { | |
nearestLeap = year + 1; | |
} else if ((year - 1) % 4 == 0 && ((year - 1) % 100 != 0 || (year - 1) % 400 == 0)) { | |
nearestLeap = year - 1; | |
} else if ((year + 2) % 4 == 0 && ((year + 2) % 100 != 0 || (year + 2) % 400 == 0)) { | |
nearestLeap = year + 2; | |
} else { | |
nearestLeap = year - 2; | |
} | |
printf("%d is not a leap year. Nearest leap year is %d.\n", year, nearestLeap); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment