#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
/*
* 请使用switch语句,if...else语句完成本题
* 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办”
* 小编还是希望大家独立完成哦~
*/
int sum,feb;
if(year%4==0&&year%100!=0||year%400==0)
{
feb=29;
}
else
{
feb=28;
}
int jan,mar,may,jul,aug,oct=31;
int apr,jun,sep,nov=30;
switch(month)
{
case 1:
sum=day;
break;
case 2:
sum=day+jan;
break;
case 3:
sum=day+jan+feb;
break;
case 4:
sum=day+jan+feb+mar;
break;
case 5:
sum=day+jan+feb+mar+apr;
break;
case 6:
sum=day+jan+feb+mar+apr+may;
break;
case 7:
sum=day+jan+feb+mar+apr+may+jun;
break;
case 8:
sum=day+jan+feb+mar+apr+may+jun+jul;
break;
case 9:
sum=day+jan+feb+mar+apr+may+jun+jul+aug;
break;
case 10:
sum=day+jan+feb+mar+apr+may+jun+jul+aug+sep;
break;
case 11:
sum=day+jan+feb+mar+apr+may+jun+jul+aug+sep+oct;
break;
case 12:
sum=day+jan+feb+mar+apr+may+jun+jul+aug+sep+oct+nov;
break;
default:printf("一年当中只有12个月哦~");
break;
}
printf("%d年%d月%d日这一天,是该年中的第%d天",year,month,day,sum);
return 0;
}
int jan,mar,may,jul,aug,oct=31;
int apr,jun,sep,nov=30;这两句错了,每个月都需要单独赋值。