#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"); }
10年積累的成都網(wǎng)站建設(shè)、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有青河免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
采納哦
輸入數(shù)用scanf()函數(shù);
分段用switch()函數(shù);
1、絕對(duì)值用math庫里面的abs()函數(shù)
2、e^x用math庫里面的pow(e,x)函數(shù)
3、同理指數(shù)的都有pow()函數(shù),
4、cos函數(shù)也是math庫里面的double cos(double x)函數(shù)
補(bǔ)充:對(duì)于自變量x的不同的取值范圍,有著不同的對(duì)應(yīng)法則,這樣的函數(shù)通常叫做分段函數(shù)。它是一個(gè)函數(shù),而不是幾個(gè)函數(shù);分段函數(shù)的定義域是各段函數(shù)定義域的并集,值域也是各段函數(shù)值域的并集。
int?fun(int?x){
int?result?=?0;
if(x0){
result?=?-x;
}else?if(x==0){
result?=?100;
}else?if(x0){
result?=?x*x+1;
}
return?result;
}
int?main(){
int?num?=?0;
scanf("%d",num);
printf("%d",fun(num));
return?0;
}
#include stdio.h
#include math.h
int main(void)
{
int repeat, ri;
double x, y;
scanf("%d", repeat);
for(ri = 1; ri = repeat; ri++){
scanf("%lf",x);
y=x=0?sqrt(x):pow(x+1,2)+2*x+1/x;
printf("f(%.2f) = %.2f\n", x, y);
}
}
#include "stdio.h"
#include "math.h"
void main()
{
float x,y;
printf("x=");
scanf("%f",x);
if(x=0)
y=x*x-2;
else
y=sqrt(5-x);
printf("y=%0.2f\n",y);
}
#include?"stdio.h"
#include?"math.h"
int?main(int?argc,char?*argv[]){
double?x,y;
printf("Input?x(R:)...\nx=");
scanf("%lf",x);
if(x5)
y=-x+3.5;
else?if(x=5??x10)
y=20-3.5*pow(x+3,7);//這里看著像7,是幾就把7改成幾
else
y=-3.5+sin(x);
printf("y?=?%g\t(x==%g)\n",y,x);
return?0;
}
運(yùn)行樣例: