根據條件求y的值:

我試圖這樣做,但有些事情是錯誤的,或者我沒有做對,所以我需要一些幫助
#include <stdio.h>
int x, y;
int main() {
scanf("%d", &x);
if (x < 5)
y = x * x - 3 * x 4;
else
y = x 7;
printf("%d", y);
return 0;
}
uj5u.com熱心網友回復:
不應該是:
if (x<-4) {
y=x 5;
} else if (x>=-4 && x<=7) {
y=x*x-3*x;
} else {
y=x*x*x 2*x
}
uj5u.com熱心網友回復:
在這里,您的分段函式在其域中有 3 個段。你必須把你的條件分成三個部分。你的語法是這樣的:
if(condition 1){
<statement 1>
}
else if(condition 2){
<statement 2>
}
else {
<statement 3>
}
或者您可以使用三個“if”陳述句來檢查輸入值。
if(condition 1) {
<statement 1>
}
if(condition 2) {
<statement 2>
}
if(condition 3) {
<statement 3>
}
...
...
...
希望你能理解。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/344270.html
標籤:C 11
上一篇:python實作中國象棋
