#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
int sum;/*sum是总天数*/
if(year%4==0||year%400==0)
{
switch(month)
case 1:sum=day;break;
case 2:sum=31+day;break;
case 3:sum=60+day;break;
case 4:sum=91+day;break;
case 5:sum=121+day;break;
case 6:sum=152+day;break;
case 7:sum=182+day;break;
case 8:sum=213+day;break;
case 9:sum=244+day;break;
case 10:sum=274+day;break;
case 11:sum=305+day;break;
case 12:sum=335+day;break;
}
else
{
switch(month)
case 1:sum=day;break;
case 2:sum=31+day;break;
case 3:sum=61+day;break;
case 4:sum=92+day;break;
case 5:sum=122+day;break;
case 6:sum=153+day;break;
case 7:sum=183+day;break;
case 8:sum=214+day;break;
case 9:sum=245+day;break;
case 10:sum=275+day;break;
case 11:sum=306+day;break;
case 12:sum=336+day;break;
}
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
return 0;
}
仅供参考,遗漏了switch后面的{ },“第%d天",year”中的逗号(,)误用了中文格式
#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
int sum;/*sum是总天数*/
if(year%4==0||year%400==0)
{
switch(month)
{
case 1:sum=day;break;
case 2:sum=31+day;break;
case 3:sum=60+day;break;
case 4:sum=91+day;break;
case 5:sum=121+day;break;
case 6:sum=152+day;break;
case 7:sum=182+day;break;
case 8:sum=213+day;break;
case 9:sum=244+day;break;
case 10:sum=274+day;break;
case 11:sum=305+day;break;
case 12:sum=335+day;break;
default:break;
}
}
else
{
switch(month)
{
case 1:sum=day;break;
case 2:sum=31+day;break;
case 3:sum=61+day;break;
case 4:sum=92+day;break;
case 5:sum=122+day;break;
case 6:sum=153+day;break;
case 7:sum=183+day;break;
case 8:sum=214+day;break;
case 9:sum=245+day;break;
case 10:sum=275+day;break;
case 11:sum=306+day;break;
case 12:sum=336+day;break;
default:break;
}
}
printf("%d年%d月%d日是该年的第%d天",year,month,day,sum);
return 0;
}