唐叔
2015-08-13 10:43
int sum;
switch (month)
{
case 1:sum=0;break;
case 2:sum=28;break;
case 3:sum=(28+31);break;
case 4:sum=(28+31+30);break;
case 5:sum=(28+31+30+31);break;
case 6:sum=(28+31+30+31+30);break;
case 7:sum=(28+31+30+31+30+31);break;
case 8:sum=(28+31+30+31+30+31+31);break;
case 9:sum=(28+31+30+31+30+31+31+30);break;
case 10:sum=(28+31+30+31+30+31+31+30+31);break;
case 11:sum=(28+31+30+31+30+31+31+30+31+30);break;
case 12:sum=(28+31+30+31+30+31+31+30+31+30+31);break;
default: ;
}
if(year%400==0||(year%400!=0&&year%4==0))
{
sum=sum+day+1;
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
}
else
{
sum=sum+day;
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
}
int sum;
switch (month)
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=(28+31);break;
case 4:sum=(28+31+31);break;
case 5:sum=(28+31+30+31);break;
case 6:sum=(28+31+30+31+31);break;
case 7:sum=(28+31+30+31+30+31);break;
case 8:sum=(28+31+30+31+30+31+31);break;
case 9:sum=(28+31+30+31+30+31+31+31);break;
case 10:sum=(28+31+30+31+30+31+31+31+30);break;
case 11:sum=(28+31+30+31+30+31+31+31+30+31);break;
case 12:sum=(28+31+30+31+30+31+31+31+30+31+30);break;
default:break ;
}
if(year%400==0||(year%100!=0&&year%4==0))
{
sum=sum+day+1;
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
}
else
{
sum=sum+day;
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
}
/*上一个答案并没有仔细地看完,改得草率,是错的,抱歉。题主的主要问题是对个月份的天数不太清晰,切闰年的定义也有待百度*/
int sum;
switch (month)
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=(28+31);break;
case 4:sum=(28+31+30);break;
case 5:sum=(28+31+30+31);break;
case 6:sum=(28+31+30+31+30);break;
case 7:sum=(28+31+30+31+30+31);break;
case 8:sum=(28+31+30+31+30+31+31);break;
case 9:sum=(28+31+30+31+30+31+31+30);break;
case 10:sum=(28+31+30+31+30+31+31+30+31);break;
case 11:sum=(28+31+30+31+30+31+31+30+31+30);break;
case 12:sum=(28+31+30+31+30+31+31+30+31+30+31);break;
default: ;
}
if(year%400==0||(year%400!=0&&year%4==0))
{
sum=sum+day+1;
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
}
else
{
sum=sum+day;
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
}
C语言入门
926022 学习 · 20793 问题
相似问题