大家知道闰年的判断标准是,该年份能被4整除,但不能被100整除;该年份能被4整除,同时又能被400整除;大家也明白如果一个数能被400整除,同样也能被4整除。经过上面的分析,编写代码如下:
- #include <stdio.h>
-
-
int main(int argc, char* argv[])
-
{
-
int year;
-
printf("please input a year:\n");
-
scanf("%d",&year);
-
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
-
{
-
printf("%d is leap year!\n",year);
-
}
-
else
-
{
-
printf("%d is not leap year!\n",year);
-
}
-
return 0;
-
}
阅读(584) | 评论(0) | 转发(0) |