1. 代碼如下,3)需要實(shí)際運(yùn)行時(shí)輸入測(cè)試
創(chuàng)新互聯(lián)是一家專(zhuān)業(yè)提供永定企業(yè)網(wǎng)站建設(shè),專(zhuān)注與成都做網(wǎng)站、成都網(wǎng)站制作、H5頁(yè)面制作、小程序制作等業(yè)務(wù)。10年已為永定眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。
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;
}
#includestdio.h
int?main()
{
int?x,y;
scanf("%d",x);
if(x-10)
y=0;
else?if(x100)?y=5*x+1;
else
??y?=?5*x?+?1;?//這個(gè)表達(dá)式的值是什么啊
printf("%d\n",y);
return?0;
}
簡(jiǎn)單寫(xiě)一下主函數(shù)
int x,y;
printf("x=");
scanf("%d",x);
if(x==0){
y=-1;
printf("y=%d",y);}
else if(x0){
y=x;
printf("y=%d",y);}
else if(x0x10){
y=x+1;
printf("y=%d",y);}
else{
printf("****不在范圍內(nèi)");}
return 0;
寫(xiě)法1
if (x-5 x0) y = x;
if (x == 0) y=x-1;
if (x0 x10) y = x+1;
寫(xiě)法2
if (x-5 x10)
{
y=x; //在這個(gè)范圍,不論怎樣,先把y賦值為x
if (x=0) //在這個(gè)范圍,需要對(duì)y值做修改
{
y = y-1; //先把y-1再說(shuō),對(duì)應(yīng)x=0的情況,如果x!=0,那么我們?cè)俅涡薷?/p>
if(x0)
y = y+2; //剛剛y-1了,所以需要+2
}
}
寫(xiě)法3,終于是正常點(diǎn)的做法了
if (x-5 x0) y=x;
else
{
if (x10)
{
if (x==0) y=x-1;
else y=x+1;
}
}
寫(xiě)法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;
}
#include
int?main()
{
int?x,y;
scanf("%d",x);
if(0xx10)?y=3*x+2;
else
{if(x=0)?y=0;
else
{if?(x0)?y=x*x;
else?printf("go?die\n");
}
}
printf("%d",y);
return?0;
}該程序的分段函數(shù)如下:
f(x)=3x+2? (0x10)
f(x)=1???????? (x=0)
f(x)?=?x*x??? (x0)
#include stdio.h
#include math.h
void main()
{
float x;
double y;
printf("Please input the value of x:");
scanf("%f",x);
if(x=-10x=4)
{
y=fabs(x-2);
printf("y=%.2f\n",y);
}
else if(x=5x=7)
{
y=x+10;
printf("y=%.2f\n",y);
}
else if(x=8x=12)
{
y=pow(x,4);
printf("y=%.2f\n",y);
}
else
printf("No answer\n");
}
#include stdio.h
#include math.h
int main()
{
float x,y;
printf("please input x:");
scanf("%f",x);
if(x0 x!=-3)
?y = pow(x,2)+x-6;
else if(x=0 x10 x!=2 x!=3)
?y = pow(x,2)-5*x+6;
else
?y = pow(x,2)-x-1;
printf("y=%f\n",y);
return 0;
}
文章名稱(chēng):c語(yǔ)言分段函數(shù)1 c語(yǔ)言分段函數(shù)怎么寫(xiě)
URL地址:http://chinadenli.net/article24/dodcece.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開(kāi)發(fā)、標(biāo)簽優(yōu)化、云服務(wù)器、微信公眾號(hào)、App開(kāi)發(fā)、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容