菜鸟321456
2019-04-20 09:37
switch(month)
{
case 12:.....
case 11:...
}
这样就可以 ,但是如果我 选择 1月到12月正序就 就会出错
#include <stdio.h>
int main()
{
int year = 2008;
int month = 8;
int day = 8;
int val,february;
switch (month)
{
case 1:val=0;break;
case 2:val=31;break;
case 3:val=59;break;
case 4:val=90;break;
case 5:val=120;break;
case 6:val=151;break;
case 7:val=181;break;
case 8:val=212;break;
case 9:val=243;break;
case 10:val=273;break;
case 11:val=304;break;
case 12:val=334;break;
default:break;
}
val=val+day;
if (year%400==0||year%4==0&&year%100!=0)
february=1;
else
february=0;
if (february==1&&month>2){val++;}
printf("%d年%d月%d日是该年的第%d天",year,month,day,val);
return 0;
C语言入门
926210 学习 · 20797 问题
相似问题