- 2071 Shrawan · 7 marks
Check leap year
Short answer
A year is leap if divisible by 4 but not 100, or divisible by 400. Check condition and print result.
Write a program to find whether a year is leap or not.
A year is a leap year if it is divisible by 4 but not by 100, or if it is divisible by 400. Hence 2024 and 2000 are leap years; 1900 and 2023 are not.
#include <stdio.h>
int main(void)
{
int year;
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
printf("%d is not a leap year\n", year);
return 0;
}
Output for 2024:
Enter a year: 2024 is a leap year
Other test results: 2000 is a leap year, 1900 is not, 2023 is not.
Explanation
year % 4 == 0 && year % 100 != 0covers ordinary leap years (2024).year % 400 == 0covers century years such as 2000; 1900 is divisible by 100 but not by 400, so it is not leap.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Check triangular number · Computer Programming, chapter 5
- nth Fibonacci term prime check · Computer Programming, chapter 6
- Check string consists of alphabet only · Computer Programming, chapter 7
- Palindrome check in FORTRAN · Computer Programming, chapter 11
- Armstrong number using recursion · Computer Programming, chapter 6
- Palindrome string using function · Computer Programming, chapter 7
- JFET ID and VDS (VP -5.5 V, IDSS 10 mA), pinch-off check · Electronics Devices and Circuit, chapter 3 · asked 3×
- JFET ID and VDS (VP -3.5 V, IDSS 10 mA), pinch-off check · Electronics Devices and Circuit, chapter 3 · asked 3×
- Check y(t) = x(t-2) + x(2-t) · Data Communication, chapter 2
- Check linearity/TI: log(x(t)), t·x(t) · Data Communication, chapter 2