N7288043
2020-08-06 20:34
#include <stdio.h>
int main()
{
int nian;
int yue;
int ri;//年月日
int i=0;
printf("请输入年月日:");
scanf("%d %d %d",&nian,&yue,&ri);
switch(yue)
{
case 12:
i+=30;
case 11:
i+=31;
case 10:
i+=30;
case 9:
i+=31;
case 8:
i+=31;
case 7:
i+=30;
case 6:
i+=31;
case 5:
i+=30;
case 4:
i+=31;
case 3:
if((nian%400==0)||(nian%4==0&&nian%100!=0))
{
i+=29;
}
else
i+=28;
case 2:
i+=31;
case 1:
i+=ri;
break;
}
printf("该天是该年的第%d天\n",i);
return 0;
}
没看懂switch
swich没看懂,可以解释一下吗?为什么要倒着些,而且最后才有break,怎么让程序判断到8个月呢?
C语言入门
926210 学习 · 20797 问题
相似问题