运行平台:vs2010
//判断是否是闰年
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
printf("please input a year: n=");
while(scanf("%d",&n)!=EOF)
{
if(n%4!=0)
printf("%d不是闰年\n",n);
else if(n%100!=0)
printf("%d是闰年\n",n);
else if(n%400!=0)
printf("%d不是闰年\n",n);
else
printf("%d是闰年\n",n);
}
system("pause");
return 0;
}
方法二:
#include "stdio.h"
int main()
{
int year;
printf("please input a year: ");
while( scanf("%d",&year)!=EOF)
{
if (year%4==0)
{
if (year%100==0)
{
if (year%400==0)
printf("%d is a leap year!\n",year);
else
printf("%d is not a leap year!\n",year);
}
else
printf("%d is a leap year!\n",year);
}
else
printf("%d is not a leap year!\n",year);
}
return 0;
}