计算下列分段函数的值,x的值由键盘输入 c语言输入


如下:祥滑

#include <stdio.h>

#include <math.h>

int main()

{

float x, result;

printf("请输入x的值:");

scanf("%f",&x);

if(x <= 0)

{

result = 0;

}

else if(x <= 10)

{

result = sqrt(x);

}

else

{

result = 2 * x + 3;

}

printf("%f",result);

return 0;

}

扩展资料:

c语言计算分段函数凳宴液值的简枣物单代码:

#include <stdio.h>

#include <math.h>

int main()

{

double x,y;

printf("input x:\n");

scanf("%lf",&x);

if (x< -1.0) y=x*x*x-1;

else if (x >=-1 && x <= 1) y=-3*x+1;

else if (x>1 && x <=10) y=3*exp(2*x-1)+5;

else y = 5*x + 3.0* log10(2*x*x-1) -13;

printf("%.2lf\n",y);

return 0;

}



void main()
{

double x,y;
scanf("%f",&x);
if(x<尘简=0)
{
y=0;
}
else if(x>陪培10)
{
y=2*x+3;
}
else
{
y=sqrt((double)x);
}

printf("输出Y是派乱裤%f",y);
}
已写好:
#include <stdio.h>
#include <math.h>
int main()
{
float x, result;

printf("请输入x的灶昌巧孝值隐宽扒:");
scanf("%f",&x);

if(x <= 0)
{
result = 0;
}
else if(x <= 10)
{
result = sqrt(x);
}
else
{
result = 2 * x + 3;
}
printf("%f",result);
return 0;
}