判断一个数是不是闰年(函数调用)
#include <stdio.h>
#include <stdlib.h>
int IsLeapYear(int year){ //返回1,闰年。返回0,不是闰年。
//闰年有世纪闰年和普通闰年
//也可 (year % 100 != 0 && year % 4 == 0) || (year % 400 == 0)
if (year % 100 == 0){
if(year % 400 == 0){ //世纪闰年
return 1;
}
return 0;
}
else {
if (year % 4 == 0){ //普通闰年
return 1;
}
return 0;
}
}
int main()
{
printf("%d\n", IsLeapYear(2020));
system("pause");
return 0;
}
浙公网安备 33010602011771号