2020-10-04

    科技2022-07-20  121

    练习2-11 计算分段函数[2] (10 分)

    注:可在头文件中包含math.h,并调用sqrt函数求平方根,调用pow函数求幂。

    输入格式:

    输入在一行中给出实数x。

    输出格式:

    在一行中按“f(x) = result”的格式输出,其中x与result都保留两位小数。

    输入样例1:

    10

    输出样例1:

    f(10.00) = 3.16

    输入样例2:

    -0.5

    输出样例2:

    f(-0.50) = -2.75 #include<stdio.h> #include<math.h> int main() { double x,y; scanf("%lf",&x); if(x>0||x==0) { y=sqrt(x); } else { y=pow((x+1),2)+2*x+1.0/x; } printf("f(%.2lf) = %.2lf\n",x,y); return 0; }

     

    Processed: 0.009, SQL: 8