//輸入格式例如:2016年1月1號,,應寫為2016/1/1#include"stdio.h"?int main()?{ int year,month,day,sumday=0; scanf("%d/%d/%d",&year,&month,&day);//個位數的前面不加0,例如8月寫成8,而不是08。 switch(month) { case 1:{printf("sumday=%d",sumday+day);break;} sumday+=31; case 2: {printf("sumday=%d",sumday+day);break;} if((year%100!=0&&year%4==0)||year%400==0) { sumday=sumday+29; } else { sumday=sumday+28; } case 3:{printf("sumday=%d",sumday+day);break;} sumday=sumday+31; case 4:{printf("sumday=%d",sumday+day);break;} sumday+=30; case 5:{printf("sumday=%d",sumday+day);break;} sumday+=31; case 6:{printf("sumday=%d",sumday+day);break;} sumday+=30; case 7:{printf("sumday=%d",sumday+day);break;} sumday+=31; case 8:{printf("sumday=%d",sumday+day);break;} sumday+=31; case 9:{printf("sumday=%d",sumday+day);break;} sumday+=30; case 10:{printf("sumday=%d",sumday+day);break;} sumday+=31; case 11:{printf("sumday=%d",sumday+day);break;} sumday+=30; case 12:{printf("sumday=%d",sumday+day);break;} default:printf("error\n"); break; } return 0;?}//為什么輸入2016/12/31,結果顯示確實“sum=31”
請教各位大神如何解決這個問題(switch-case語句中)
慕粉1600176492
2016-10-29 19:27:04