4.17.为什么2月30日不提示输入有误
#include <stdio.h>
int main()
{
int year = 2008,month = 8,day = 8;
if(month>12||month<1||day<1||day>31)
{
printf("输入有误");
}
else
{
if(month = 4,month = 6,month = 9,month = 11)
{
if(day==31)
{
printf("输入有误");
}
else
{
sum();
}
}
else if(month==2)
{
if(year%400==0 || (year%4 == 0 && year%100 != 0))
{
if(day>=29)
{
printf("输入有误");
}
else
{
sum();
}
}
else
{
if(day>=28)
{
printf("输入有误");
}
else
{
sum();
}
}
}
else
{
sum();
}
}
return 0;
}
int sum()
{
int ear = 2008,onth = 8,ay = 8,Today=0, i;
for(i=1;i<onth;i++)
{
switch(i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
Today += 31;
break;
case 2:
if(ear%400==0 || (ear%4 == 0 && ear%100 != 0))
{
Today += 29;
}
else
{
Today += 28;
}
break;
case 4:
case 6:
case 9:
case 11:
Today += 30;
break;
default:
break;
}
}
Today += ay;
printf("%d年%d月%d日是该年的第%d天",ear,onth,ay,Today);
return 0;
}