1. 代碼如下,3)需要實際運行時輸入測試
成都創(chuàng)新互聯(lián)公司基于成都重慶香港及美國等地區(qū)分布式IDC機房數(shù)據(jù)中心構(gòu)建的電信大帶寬,聯(lián)通大帶寬,移動大帶寬,多線BGP大帶寬租用,是為眾多客戶提供專業(yè)服務(wù)器托管雅安報價,主機托管價格性價比高,為金融證券行業(yè)服務(wù)器托管,ai人工智能服務(wù)器托管提供bgp線路100M獨享,G口帶寬及機柜租用的專業(yè)成都idc公司。
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;
}
幫你改了下代碼,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;//缺少分號
}
{ f=x+1; if ( f0 ) f=-f; }
x=5
x,f);
計算下列分段函數(shù)
f(x,y)= 2X2+3x+1/(x+y) (x=0,y0)
f(x,y)=2X2+3x+1/(1+y2)(x=0,y=0)
f(x,y)=3sin(x+y)/ 2X2+3X+1? (x0)
擴展資料:
已知函數(shù)f(x)= 求f(3)的值。
解:由3∈(-∞,6),知f(3)=f(3+2)=f(5),
又5∈(-∞,6),所以f(5)=f(5+2)=f(7).
又由7∈[6,+∞)所以f(7)=7-2=5,因此,f(3)=5。
求分段函數(shù)的函數(shù)值的方法:先確定要求值的自變量屬于哪一段區(qū)間,然后按該段的表達式去求值,直到求出值為止。
參考資料來源:百度百科-分段函數(shù)
#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");
}
#includestdio.h
void?main()
{?
float?x,y;
scanf("%f",x);
if(x0)
y=x*x;
else?if(x==0)
y=2*x-1;
else?
y=-3*x*x-1?;//這里少個分號
printf("%.2f",y);
}
輸入數(shù)用scanf()函數(shù);
分段用switch()函數(shù);
1、絕對值用math庫里面的abs()函數(shù)
2、e^x用math庫里面的pow(e,x)函數(shù)
3、同理指數(shù)的都有pow()函數(shù),
4、cos函數(shù)也是math庫里面的double
cos(double
x)函數(shù)
自己動手吧,我已經(jīng)把難點全部說出來了!
希望可以幫到你,如果滿意請采納!
當前名稱:c語言分段函數(shù)實驗題 c++分段函數(shù)問題描述
鏈接地址:http://muchs.cn/article2/docscoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、網(wǎng)站設(shè)計、定制網(wǎng)站、電子商務(wù)、服務(wù)器托管、網(wǎng)站設(shè)計公司
聲明:本網(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)