C语言的题目:从键盘上输入一个年份,判断它是否为闰年;并显示其判断结果

2025-01-07 03:11:47
推荐回答(2个)
回答1:

判断条件:
1、能被400整除的,肯定是闰年;
2、能被4整除,但是不能被100整除的,是闰年;
3、其他的都是非闰年。

回答2:

#include
void main ( )

{

int year,leap;

printf ("Please enter year:\n");

scanf ("%d",&year);

if (year%400==0)

leap=1;

else

if ((year%4==0)&&(year%100!=0))

leap=1;

else

leap=0;

if (leap!=0)

printf ("%d is a leap year.\n",year);

else

printf ("%d is not a leap year.\n",year);

}