有沒有大哥幫忙看一下哪里不對
判斷大小月
請用程序實現: 輸入一個表示月份的整數,判斷它是大月還是小月。如果是大月,輸出solar month
;如果是小月,輸出lunar month
; 如果輸入數據不合法, 則輸出error
。
注意: 如果一個月有31
天則被稱為大月;如果一個月有30
天則被稱為小月,2
月既不是大月也不是小月,在本題中,將2
月劃分到小月。
#include <stdio.h>
int main () {
??? // TODO 請在此處編寫代碼,完成題目要求
??? int month=2;
??? if(month==1||3||5||7||8||10||12)
??? {
??????? printf("solar month");
??? }
??????? else if(month==2||4||6||9||11)
??????? {
??????????? printf("lunar month");
??????? }
??? else
??? {
??????? printf("error");
??? }
??? return 0;
}
2020-03-13
int main(void) {?
int month=2;
? ? if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
? ? {
? ? ? ? printf("solar month\n");
? ? }
? ? else if((month==2)||(month==4)||(month==6)||(month==9)||(month==11))
? ? ? ? {
? ? ? ? ? ? printf("lunar month\n");
? ? ? ? }
? ? else
? ? {
? ? ? ? printf("error\n");
? ? }
? ? return 0;
}
2020-03-13
在你的if(month==1||3||5||7||8||10||12) 代碼中,(程序認為你的意思是:2=1,或者2=3,或2=5....)
然后,month=2 為"True",就直接輸出"solar month",不再執行下面的語句。