浙大版《C語(yǔ)言程序設(shè)計(jì)(第3版)》題目
練習(xí)2-11 計(jì)算分段函數(shù)[2] (10分)
本題目要求計(jì)算下列分段函數(shù)f(x)的值:
image.png
注:可在頭文件中包含math.h
玷坠,并調(diào)用sqrt
函數(shù)求平方根币狠,調(diào)用pow
函數(shù)求冪雷滚。
輸入格式:
輸入在一行中給出實(shí)數(shù)x食茎。
輸出格式:
在一行中按“f(x) = result”的格式輸出有额,其中x與result都保留兩位小數(shù)渠啊。
輸入樣例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;
if(scanf("%lf",&x)==1){
if(x>=0)y=sqrt(x);
else y=(x+1)*(x+1)+2*x+1/x;
printf("f(%.2lf) = %.2lf\n",x,y);
}
return 0;
}