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