感觉这个方法更简便一点,只需要输入每个月份的天数,可以自动加总的
#include <stdio.h>
int main()
{
int year = 2008;
int month = 8;
int day = 8;
int sum=0;
month=month-1;
switch (month)
{
case 12: sum+=31;
case 11: sum+=30;
case 10: sum+=31;
case 9: sum+=30;
case 8: sum+=31;
case 7: sum+=31;
case 6: sum+=30;
case 5: sum+=31;
case 4: sum+=30;
case 3: sum+=31;
case 2: sum+=28;
case 1: sum+=31;
break;
}
sum+=day;
if((year%400==0)||(year%100!=0&&year%4==0))
{
if(month>2)
sum+=1;
}
printf("%d",sum);
return 0;
}