1. 如果年份能被4整除但不能被100整除,则为闰年。
2. 如果年份能被400整除,则为闰年。
3. 其他情况下均为平年。
include
int isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
return 1; // 是闰年
} else {
return 0; // 不是闰年
}
}
int main() {
int year;
printf("请输入一个年份: ");
scanf("%d", &year);
if (isLeapYear(year)) {
printf("%d 是闰年\n", year);
} else {
printf("%d 不是闰年\n", year);
}
return 0;
}