该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
有验证月份,没有验证日。
#include
int main()
{
int year,mouth,day,sum=0,days=0;
printf("input year mouth day:");
scanf("%d%d%d",&year,&mouth,&day);
switch(mouth)
{
case 1:days=sum+day;
break;
case 2:days=sum+31+day;
break;
case 3:days=sum+59+day;
break;
case 4:days=sum+90+day;
break;
case 5:days=sum+120+day;
break;
case 6:days=sum+151+day;
break;
case 7:days=sum+181+day;
break;
case 8:days=sum+212+day;
break;
case 9:days=sum+243+day;
break;
case 10:days=sum+273+day;
break;
case 11:days=sum+304+day;
break;
case 12:days=sum+334+day;
break;
default:printf("data error");
sum++;
break;
}
if(sum==0)
{if(mouth>2&&(year%400==0||(year%100!=0&&year%4==0)))
{
days++;
}
printf("days=%d",days);
}
}