1:你要清楚什么样的年份才是闰年(能被4整除且不能被100整除或者能被400整除的,参考http://baike.baidu.com/view/29649.htm)
2:判断语句
if( ((0 == year%4)&&(0 != year%100)) ||(0 == year %400) )
{
//满足该条件的yeat就是闰年。
}
3:希望对你有帮助
#include
int main() {
int year;
printf("输入你要查询的年份:\n");
scanf_s("%d", &year);
if (year%100!=0&&year%4==0||year%400==0)
{
printf("%d年是闰年\n", year);
}
else
{
printf("%d年是平年", year);
}
} // 判断年份是否为闰年
我们主要就是判断是否是闰年符合一个即可: 1,能被4整除,但不能被100整除 如2008.2,能被4整除又能被400整除,如2000.我们可以用一个逻辑表达((year%4==0&&year%100!==0)||year%400==0
# include
int main()
{
int year;
printf("Input a year number:\n");
scanf("%d",&year);
if((year%4==0 && year%100!=0) || (year%400==0))
printf(" %d is a leap year.",year);
else
printf(" %d is not a leap year.",year);
return 0;
}
# include
main()
{
int year;
printf("Input a year number:\n");
scanf("%d",&year);
if((year%4==0 && year%100!=0) || (year%400==0))
printf(" %d 是闰年.",year);
else
printf(" %d 不是闰年.",year);
}