閏年規則(格里曆):
#include <stdio.h>
int is_leap(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int main() {
int year;
printf("請輸入年份:");
scanf("%d", &year);
printf("%d年%s閏年\n", year, is_leap(year) ? "是" : "非");
return 0;
}
請輸入年份:2000
2000年是閏年
請輸入年份:1995
1995年非閏年
year % 4 == 0 → 1900 會被誤判為閏年。