求C语言程序--判断某一年是否是闰年

判定2000——2500年中的每一年是否是闰年,将结果输出。
闰年的条件是:
(1)能被4整除,但不能被100整除的年份都是闰年。
(2)能被100整除,又能被400整除的年份是闰年。

还有,为什么是否满足是闰年的条件是上面2条,那是书上的提示,我不解啊!~

这个就是闰年的定义啊~是天文学家推出来的,这个就不用理解了吧^_^

#include "stdafx.h"
#include <iostream>
using namespace std;

bool CheckYear(int nYear)
{
if ((nYear % 4 == 0 && nYear % 100 != 0 )|| nYear % 400 == 0)
return true;

return false;
}

void main()
{
for (int nYear = 2000; nYear <= 2500; ++nYear)
{
if (CheckYear(nYear))
cout << nYear << endl;
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-05-04
#include<stdio.h>
void main()
{
int leap(int m);
int i,j;
for(i=2000;i<2501;i++)
{
j=leap(i);
if(j==1)printf("%d is leap year!\n",i);
}
}
int leap(int m)
{
int x;
x=0;
if(m%400==0) x=1;
if(m%100!=0&&m%4==0)x=1;
return x;
}
第2个回答  2008-05-04
闰年的定义一直都是这样的,比如说2000是闰年而2100就不是。你记住就行了。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网