寫法1
成都創(chuàng)新互聯(lián)長期為上千家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為梁河企業(yè)提供專業(yè)的網(wǎng)站制作、成都做網(wǎng)站,梁河網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
if (x-5 x0) y = x;
if (x == 0) y=x-1;
if (x0 x10) y = x+1;
寫法2
if (x-5 x10)
{
y=x; //在這個范圍,不論怎樣,先把y賦值為x
if (x=0) //在這個范圍,需要對y值做修改
{
y = y-1; //先把y-1再說,對應(yīng)x=0的情況,如果x!=0,那么我們再次修改
if(x0)
y = y+2; //剛剛y-1了,所以需要+2
}
}
寫法3,終于是正常點的做法了
if (x-5 x0) y=x;
else
{
if (x10)
{
if (x==0) y=x-1;
else y=x+1;
}
}
寫法4
switch(x)
{
case 0:
y=x-1;
break;
case -4;
case -3;
case -2;
case -1;
y=x;
break;
case 1;
case 2;
case 3;
case 4;
case 5;
case 6;
case 7;
case 8;
case 9;
y=x+1;
break;
}
幫你改了下代碼,VC6測試通過,自己看看吧。
#includestdio.h
int main()
{
float x,y;//根據(jù)給定的測試用例,x,y應(yīng)該為float型
scanf("%f",x);//x為float型,所以改為%f
if(x20)
{
y=x+100;
}
else if(x=20x=100)
{
y=x;
}
else
y=x-100;
printf("x=%f,y=%f\n",x,y);
return 0;//缺少分號
}
1. 代碼如下,3)需要實際運行時輸入測試
int main(void)
{
double x, y, f;
printf("Please input 2 double number in the form of x y:\n");
scanf("%lf%lf", x, y);
if(x=0 y0)
f = 2*x*x + 3*x +1/(x+y);
else if(x=0 y=0)
f = 2*x*x + 3*x +1/(1+y*y);
else
f = 3*sin(x+y)/(2*x*x) + 3*x + 1;
printf("x=%lf, y=%lf, f(x, y)=%lf\n", x, y, f);
return 0;
}
2.代碼如下
#include stdio.h
#includemath.h
int main(void)
{
double x, y, f;
printf("Please input 2 double number in the form of x y:\n");
scanf("%lf%lf", x, y);
if(x=0)
{
if(y0)
f = 2*x*x + 3*x +1/(x+y);
else
f = 2*x*x + 3*x +1/(1+y*y);
}
else
f = 3*sin(x+y)/(2*x*x) + 3*x + 1;
printf("x=%lf, y=%lf, f(x, y)=%lf\n", x, y, f);
return 0;
}
3.代碼如下
#include stdio.h
int main(void)
{
int score = 0;
printf("Please input a score between 0-100:\n");
scanf("%d", score);
if(score0 || score100)
printf("Wrong input of score!\n");
else if(score=90 score=100)
printf("A\n");
else if(score=80 score=89)
printf("B\n");
else if(score=70 score=79)
printf("C\n");
else if(score=60 score=69)
printf("D\n");
else
printf("E\n");
return 0;
}
標題名稱:c語言雙分支結(jié)構(gòu)分段函數(shù) c語言四段分段函數(shù)
鏈接URL:http://muchs.cn/article6/docogig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司、定制開發(fā)、網(wǎng)站排名、企業(yè)網(wǎng)站制作、品牌網(wǎng)站建設(shè)、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)