C Leap Year Program: Complete Guide
The condition for determining if a year is a leap year is:
- A year is a leap year if it can be divided by 4 but not by 100.
- A year that can be evenly divided by 400 is also a leap year.
Here is a program written in the C language to determine if it is a leap year:
#include <stdio.h>
int main() {
int year;
printf("请输入一个年份:");
scanf("%d", &year);
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
printf("%d年是闰年\n", year);
} else {
printf("%d年不是闰年\n", year);
}
return 0;
}
The program will determine if a year inputted by the user is a leap year and display the result.