您的位置:首页 > 其它

判断1000年---2000年之间的闰年

2016-05-18 13:20 225 查看
判断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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: