C语言编程 求分段函数的值

2025-06-29 07:51:15
推荐回答(3个)
回答1:

#include
#include

void main()
{
int x;
float Y;
printf("please input x\n");
scanf("%d",&x);
if(x > 0)
Y = 1 + exp(x); //数学函数,计算e的x次方
else if(x == 0)
Y = 1;
else
Y = log(x * x); //数学函数,计算x的平方,以e为底
printf("%.4f\n",Y);
}

please input x
0
1.0000
Press any key to continue

please input x
1
3.7183
Press any key to continue

please input x
-2
1.3863
Press any key to continue

回答2:

#include
#include
void main()
{
double x=0;
double y=0;
printf(" 请输入x\n")
scanf("%ld",&x);
if(x==0)
y=1;
else if(x<0)
y=1+e^x;
else if(x>0)
y=axp(x);
}

}

回答3:

#include
...
int x;
double y;
if(x>o) y=1+exp(x);
else if(x=0) y=1;
else y=2*log(x);