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

#include <stdio.h>
/*
enter a year,then judge it's leap year or not
2014-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,谢谢!

你可能感兴趣的:(Linux C一站式学习习题答案5.1.1)