用c语言编写表达式并通过程序求值

2x^2+2|3x+4|+5。 当x=2时

可得如下代码:

#include<stdio.h>

double fun(double x)
{
    double t = 3*x+4>0?3*x+4:-3*x-4;
    t*=2;
    return (t+2*x*x+5);
}
int main()
{
    double x, y;
    scanf ("%lf", &x);
    y = fun(x);
    printf ("%f\n", y);
    return 0;
}
温馨提示:答案为网友推荐,仅供参考
相似回答