int year = 2008;
int month = 8;
int day = 8;
/*
* 请使用switch语句,if...else语句完成本题
* 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办”
* 小编还是希望大家独立完成哦~
*/
int run[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int ping[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int flag,i,sum;
if((year%4==0&&year%100!=0)||year%400==0)
{
flag=1;
}
else flag=0;
switch(flag)
{
case 1:
for(i=0;i<(month-1);i++)
{
sum+=run[i];
}
break;
case 0:
for(i=0;i<(month-1);i++)
{
sum+=ping[i];
}
break;
}
sum=sum+day;
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
return 0;
for(i=0;i<=(month-1);i++)
month不用减1,它取不到当前月