代码一:
#include<stdio.h> int main() { int year,leap; printf("请输入一个年份:"); scanf("%d",&year); if(year%4==0&&year%100!=0||year%400==0) { leap=1; } else { leap=0; } if (leap==1) { printf("%d是闰年! \n",year); } else { printf("%d不是闰年! \n",year); } }
代码二:
#include <stdio.h> int isleapyear(int year); int main() { int year; int leap; printf("请输入一个年份:"); scanf("%d",&year); leap=isleapyear(year); if(leap==1) { printf("%d是闰年! \n",year); } else { printf("%d不是闰年! \n",year); } return 0; } int isleapyear(int year) { if(year%4==0&&year%100!=0||year%400==0) { return 1; } else { return 0; } }