闰年的规定:
知道了由来,我们就可以写程序来判断:
#include <stdio.h>
int main() {
int year, leap;
scanf("%d",&year);
if((year%4 == 0 && year%100 != 0) || year%400 == 0)
leap = 1;
else
leap = 0;
if(leap) printf("%d is a leap year.\n",year);
else printf("%d is not a leap year.\n",year);
return 0;
}
当然,也可以分成多个 if else 语句来判断,但都没有这种直观简便。