#include <stdio.h>
int i, sum, days; //声明全局变量
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
/*
* 请使用switch语句,if...else语句完成本题
* 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办”
* 小编还是希望大家独立完成哦~
*/
for(i = 1; i <= month-1; i++){
switch(i){
case 1:
days = 31;
break;
case 3:
days = 31;
break;
case 5:
days = 31;
break;
case 7:
days = 31;
break;
case 8:
days = 31;
break;
case 10:
days = 31;
break;
case 12:
days = 31;
break;
case 2:
if((year % 4 == 0 && year % 100 != 0) || year % 400 ==0){
days = 29;
}else{
days = 28;
}
break;
default :
days = 30;
break;
}
sum=sum+days;
}
sum+=day;
printf("%d年%d月%d日是该年中的第%d天",year, month, day, sum);
return 0;
}