打印1000年到2000年之间的闰年
cpp
#include<stdio.h>
int main()
{
int a = 0;
for (int i = 1000; i <= 2000; i++)
{
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
{
printf("%d ", i);
a++;
}
}
printf("\nTotal number of leap years are %d", a);
return 0;
}
:
核心双条件(二选一成立即闰年)
- 普通闰年 :年份能被 4 整除,且 不能被 100 整除 →
year %4 ==0 && year%100 !=0 - 世纪闰年 :年份能被 400 整除 →
year %400 ==0
闰年判断公式 :(i%4==0 && i%100!=0) || i%400==0(可直接背记,刷题 / 考试高频);