输入⼀个年份year,判断year是否是闰年
闰年判断的规则:
1.
能被4整除并且不能被100整除是闰年
2.
能被400整除是闰年
#include <stdio.h>
int main()
{
int year = 0;
scanf("%d", &year);
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
{
printf("%d年是闰年\n",year);
}
}
或者我们也可以这样写
#include <stdio.h>
int main()
{
int year = 0;
scanf("%d", &year);
if ((year % 4 == 0) && (year % 100 != 0))
{
printf("%d年是闰年\n", year);
}
if (year % 400 == 0)
{
printf("%d年是闰年\n", year);
}
return 0;
}