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