請(qǐng)問switch case中case后內(nèi)容相同可以合并嗎,為什么我計(jì)算錯(cuò)誤
#include <stdio.h>
int main()?
{?
? ? /* 定義需要計(jì)算的日期 */
? ? int year = 2008;
? ? int month = 8;
? ? int day = 8;
? ? /*
? ? ?* 請(qǐng)使用switch語句,if...else語句完成本題
? ? ?* 如有想看小編思路的,可以點(diǎn)擊左側(cè)任務(wù)中的“不會(huì)了怎么辦”
? ? ?* 小編還是希望大家獨(dú)立完成哦~
? ? ?*/
? ? int date=0,i;
? ? for(i=1;i<month;i++)
? ? {switch(month)
? ? ? {
? ? ? ? case 1: case 3: case 5: case 7: case 8: case 10: case 12: date=date+31;break;
? ? ? ? case 4: case 6: case 9: case 11: date=date+30;break;
? ? ? ? case 2: if(year%4==0)
? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? date=date+29;
? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? date=date+28;
? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? }
? ? ? }
? ? ??}date=date+day;
? ? printf("date=%d\n",date);
return 0;
}
2018-06-10
好吧,打錯(cuò)一個(gè),把month改成i就成了