if else 判断闰年
#include <stdio.h>int main()
{
int year,leap;
printf("enter year: ");
scanf("%d\n",&year);
if(year %4 == 0)
{
if(year %100 == 0)
{
if(year %400 == 0)
leap = 1;
else
leap = 0;
}
else leap = 1;
}
else leap = 0;
if(leap)
printf("%d is",year);
else
printf("%d is not",year);
printf("a leap year!\n");
return 0;
}
无error
编译完跑不起来。输入2012 没反应 把 scanf 那里的 \n 去掉即可
#include <stdio.h>
int main()
{
int year, leap;
printf("enter year: ");
scanf("%d", &year);
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
leap = 1;
else
leap = 0;
}
else
leap = 1;
}
else
leap = 0;
if (leap)
printf("%d is", year);
else
printf("%d is not", year);
printf("a leap year!\n");
return 0;
}
页:
[1]