输入一个正整数repeat (0
当x >= 0时,f(x) = x^0.5,当x小于0时,f(x) = (x+1)^2 + 2x + 1/x。
输入输出示例:括号内是说明
输入
3 (repeat=3)
10
-0.5
0
输出
f(10.00) = 3.16
f(-0.50) = -2.75
f(0.00) = 0.00
--------------------------------------------------------------------------------
#include
#include
int main(void)
{
int repeat, ri;
double x, y;
scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++){
printf("f(%.2f) = %.2f\n", x, y);
}
}
后面是我做的,看一下哪儿错了,运行结果不对 #include
#include
int main(void)
{
int repeat, ri;
double x, y;
scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%lf",&x);
if(x>=0) y=sqrt(x);
else y=pow((x+1),2)+2*x+1/x;
printf("f(%.2f) = %.2f\n", x, y);
return 0;
}
}