实现函数判断year是不是润年
闰年是公历中的名词。闰年分为普通闰年和世纪闰年。
普通闰年:公历年份是4的倍数的,且不是100的倍数,为普通闰年。(如2004年就是闰年);
世纪闰年:公历年份是整百数的,必须是400的倍数才是世纪闰年(如1900年不是世纪闰年,2000年是世纪闰年)。
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int leap(int year)
{
if (year % 4 == 0 && year % 100 != 0)//普通闰年:能被4整除且不能被100整除
{
return 1;
}
else if (year % 400 == 0)//世纪闰年:能被400整除
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int year = 0;
int tep = 0;
printf("请输入要判断的年份\n");
scanf("%d", &year);
tep = leap(year);
if (tep == 1)
{
printf("闰年\n");
}
else
{
printf("平年\n");
}
return 0;
}
运行结果如下: