#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
int num=0;
switch(month)
{
case 12:num+=30;
case 11:num+=31;
case 10:num+=30;
case 9:num+=31;
case 8:num+=31;
case 7:num+=30;
case 6:num+=31;
case 5:num+=30;
case 4:num+=31;
case 3:
if(year%4==0)
{
num+=29;
}else{
num+=28;
}
case 2:num+=31;
case 1:num+=day;
}
printf("2008年8月8日是该年的第%d天",num);
return 0;
}我不是很懂qaq但是你闰年的判断方法是不对滴
break帮你找到合适的部分就跳出循环
兄弟,这个想法把我给惊叹到了!确实思路很ok。但我觉得 case 3: 那里对闰年的判断可能有些许失误
判断闰年的原则(满足二者其一即可)1.能被4整除,但不能被100整除的是闰年。2.能被100整除,又能被400整除是闰年。
//判断闰年的原则(满足二者其一即可)1.能被4整除,但不能被100整除的是闰年。2.能被100整除,又能被400整除是闰年。
if(year%100==0)
{
if(yearf%400==0)
{
num+=29;
}
else
{
num+=28;
}
}
else
{
if(year%4==0)
{
num+=29;
}
else
{
num+=28;
}
}可以,哪种好用就用哪种