C语言程序设计判断某一年是否是闰年

来源:百度知道 编辑:UC知道 时间:2024/05/26 20:39:54

#include <stdio.h>
void main()
{
int year,result=0;
printf("输入一个年份:\n");
scanf("%d",&year);
if(year%100==0)
{
if(year%400==0)
result=1;
}
else if(year%4==0)
result=1;

if(result==1)
printf("\n%d是闰年",year);
else
printf("\n%d不是闰年",year);
}

_______
已经编译好啦

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

#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)能被4整除,不能被100整除;
(2)能被400整除。