1个回答
展开全部
main()
{
int year,month,day,i=0,n=0;
printf("Please input year.month.day\n");
loop:
scanf("%d.%d.%d",&year,&month,&day);
if(month<=0||month>12||day<=0||day>31)
{
printf("Data error!Please input again.\n");
goto loop;
}
switch(month)
{
case 1:n=0;break;
case 2:n=31;break;
case 3:n=59;break;
case 4:n=90;break;
case 5:n=120;break;
case 6:n=151;break;
case 7:n=181;break;
case 9:n=243;break;
case 10:n=273;break;
case 11:n=304;break;
case 12:n=334;
}
n+=day;
if(year%400==0||(year%4==0&&year%100!=0))
i=1;
else
i=0;
if(i==1&&month>2)n++;
printf("It is the %dth day.",n);
}
参考别人后自己编的,应该是这个吧.输入某月某日计算为一年的第几天.
{
int year,month,day,i=0,n=0;
printf("Please input year.month.day\n");
loop:
scanf("%d.%d.%d",&year,&month,&day);
if(month<=0||month>12||day<=0||day>31)
{
printf("Data error!Please input again.\n");
goto loop;
}
switch(month)
{
case 1:n=0;break;
case 2:n=31;break;
case 3:n=59;break;
case 4:n=90;break;
case 5:n=120;break;
case 6:n=151;break;
case 7:n=181;break;
case 9:n=243;break;
case 10:n=273;break;
case 11:n=304;break;
case 12:n=334;
}
n+=day;
if(year%400==0||(year%4==0&&year%100!=0))
i=1;
else
i=0;
if(i==1&&month>2)n++;
printf("It is the %dth day.",n);
}
参考别人后自己编的,应该是这个吧.输入某月某日计算为一年的第几天.
参考资料: 加分哦.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |