判断1000-2000年之间的闰年,判断一年是否为闰年的标准是year%4==0同时year%100!=0,或者year%400==0
void test()
{
int count = 0;
int year = 0;
for(year = 1000;year <=2000;year++)
{
if(year % 4 == 0)
{
if(year % 100 != 0)
{
printf("%d ",year);
count++;
}
}
if(year % 400 == 0)
{
printf("%d ",year);
count++;
}
}
printf("\ncount = %d\n",count);
return 0;
}
当然,代码是可以简洁的
void test()
{
int count = 0;
int year = 0;
for (year = 1000; year <= 2000; year++)
{
if ((year % 4 == 0) && (year % 100 != 0) || (ear % 400 == 0))
{
printf("%d ", year);
count++;
}
}
printf("\ncount = %d\n", count);
return 0;
}