Challenge: Leap Year
Completed
Read a year and print leap or not leap. A year is a leap year if it can be divided by 4, except years divisible by 100 – unless they are also divisible by 400.
Input
One integer: the year.
Output
leap or not leap.
Example
Input
2024
Output
leap
Editor
C
Hints
"divisible by 4" means year % 4 == 0.
Combine the rules with && and ||, and use brackets.
Solution explanation
The year is a leap year when it is divisible by 4 but not by 100, or when it is divisible by 400.
Show solution
#include <stdio.h>
int main() {
int year;
scanf("%d", &year);
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
printf("leap\n");
} else {
printf("not leap\n");
}
return 0;
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module