int main()
{
/ 定义需要计算的日期 /
int year = 2008;
int month = 8;
int day = 8;
int sum=0;
int flag=0;
if(year%400==0||year%4==0)
{
flag=29;
}
else
{
flag=28;
}
switch(month)
{
case 1:
sum=day;break;
case 2:
sum=31+day;break;
case 3:
sum=31+flag+day;break;
case 4:
sum=62+flag+day;break;
case 5:
sum=92+flag+day;break;
case 6:
sum=123+flag+day;break;
case 7:
sum=153+flag+day;break;
case 8:
sum=184+flag+day;break;
case 9:
sum=215+flag+day;break;
case 10:
sum=245+flag+day;break;
case 11:
sum=276+flag+day;break;
case 12:
sum=306+flag+day;break;
default:
printf("亲!!一年只有12个月");
break;
}
printf("%d年%d月%d是该年的第%d天\n",year,month,day,sum);
return 0;
}
热门评论
运行提示出错了,你仔细看看