亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

有沒有大哥幫忙看一下哪里不對

判斷大小月

請用程序實現: 輸入一個表示月份的整數,判斷它是大月還是小月。如果是大月,輸出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;
}


正在回答

2 回答

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;

}


0 回復 有任何疑惑可以回復我~

在你的if(month==1||3||5||7||8||10||12) 代碼中,(程序認為你的意思是:2=1,或者2=3,或2=5....)

然后,month=2 為"True",就直接輸出"solar month",不再執行下面的語句。

0 回復 有任何疑惑可以回復我~
#1

小龍佩奇

所以要改成: 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");
2020-03-13 回復 有任何疑惑可以回復我~
#2

北淵 提問者

感謝!講得很清楚
2020-03-13 回復 有任何疑惑可以回復我~
#3

小龍佩奇 回復 北淵 提問者

也可能是因為month==1||3||5||7||8||10||12在C中計算出一個為"True"的邏輯值。 我是小白,如果回答錯了請原諒??!
2020-03-13 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

有沒有大哥幫忙看一下哪里不對

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號