#include <stdio.h>
int main()
{
int year = 2008;
int month = 8;
int day = 8;
int sum,rn;
switch(month)
{
case1:sum=0;break;
case2:sum=31;break;
case3:sum=59;break;
case4:sum=90;break;
case5:sum=120;break;
case6:sum=151;break;
case7:sum=181;break;
case8:sum=212;break;
case9:sum=243;break;
case10:sum=273;break;
case11:sum=304;break;
case12:sum=334;break;
default:printf("错误了");break;
}
if((year%4==0&&year%100!=0)||year%400==0)
{
rn=1;
}
else
{
rn=0;
}
sum=sum+day+rn;
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
return 0;
}
缺少闰年对sum的影响,主要是区分闰年时月份大于2时,sum的变化,后面可以稍加更改:
sum+=day; if(rn==1&&month>2)//闰年且月份大于2时才会考虑闰年的影响 { sun+=1; printf("%d年%d月%d日是该年的第%d天",year,month,day,sum); } else { printf("%d年%d月%d日是该年的第%d天",year,month,day,sum); }