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;

}


温馨提示:答案为网友推荐,仅供参考
相似回答