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