#include <stdio.h>
int main()
{
int year = 2008;
int month = 8;
int day = 8;
int sum;
switch(month)
{
case 1:
if(month>1)
sum=sum+31;
else
{
sum=sum+day;
break;
}
case 2:
if(month>2)
if(year%4==0)
sum=sum+29;
else
sum=sum+30;
else
{
sum=sum+day;
break;
}
case 3:
if(month>3)
sum=sum+31;
else
{
sum=sum+day;
break;
}
case 4:
if(month>4)
sum=sum+30;
else
{
sum=sum+day;
break;
}
case 5:
if(month>5)
sum=sum+31;
else
{
sum=sum+day;
break;
}
case 6:
if(month>6)
sum=sum+30;
else
{
sum=sum+day;
break;
}
case 7:
if(month>7)
sum=sum+31;
else
{
sum=sum+day;
break;
}
case 8:
if(month>8)
sum=sum+31;
else
{
sum=sum+day;
break;
}
case 9:
if(month>9)
sum=sum+30;
else
{
sum=sum+day;
break;
}
case 10:
if(month>10)
sum=sum+31;
else
{
sum=sum+day;
break;
}
case 11:
if(month>11)
sum=sum+30;
else
{
sum=sum+day;
break;
}
case 12:
sum=sum+day;
break;
}
printf("%d年%d月%d日是该年的第%d天!",year,month,day,sum);
return 0;
}
怎么会输出这么庞大的数字 - -!求大神解答!
你的break写在else下面去了,如果程序读不到break就会继续执行下面的代码,知道遇见break为止