1、编写一个布尔函数int is_leap_year(int year)
,判断参数year
是不是闰年。如果某年份能被4整除,但不能被100整除,那么这一年就是闰年,此外,能被400整除的年份也是闰年。
int main(){
int i,j;
printf("please input a number:");
scanf("%d",&i);
printf("i=%d/n",i);
j = is_leap_year(i);
if (j){
printf("is leap year/n");
}
else{
printf ("not leap year/n");
}
}
int is_leap_year(int year){
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
return 1;
else
return 0;
}
在is_leap_year函数中,根据判断信息进行判断。进行返回如果闰年返回1,不是闰年返回0;在此函数中涉及到优先级的问题。