Linux C一站式学习习题答案5.1.1

来源:互联网 发布:2016新能源数据 编辑:程序博客网 时间:2024/05/21 09:41

#include <stdio.h>/*enter a year,then judge it's leap year or not2014-01-16 hourui*/int is_leap_year(int year){if (year%4 == 0) { if (year%100==0){if (year%400==0)  printf("%d is leap year\n",year); else  printf("%d is not lear year\n",year);} else    printf("%d is leap year\n",year); }else printf("%d is not leap year\n",year);return 0;}int main (){int a;printf("please enter a year:");scanf("%d",&a);is_leap_year(a);return 0;}

编写一个布尔函数int is_leap_year(int year),判断参数year是不是闰年。如果某年份能被4整除,但不能被100整除,那么这一年就是闰年,此外,能被400整除的年份也是闰年。

转载请注明源地址:http://blog.csdn.net/whorus1/article/list/2,谢谢!

0 0
原创粉丝点击