C语言的问题,谁能帮我看看哪里错了啊

来源:百度知道 编辑:UC知道 时间:2024/06/11 08:27:04
程序填空,不要改变与输入输出有关的语句。
输入一个正整数repeat (0<repeat<10),做repeat次下列运算:
输入 x,计算并输出下列分段函数 f(x) 的值(保留2位小数),请调用 sqrt 函数求平方根,调用 pow 函数求幂。
当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 <stdio.h>
#include <math.h>
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 <stdio.h>
#include <math.h>
int main(void)
{
int repeat, ri;
double x, y;

scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++){
if(x>=0){
y=sqrt(x);}
else{
y=pow((1+x

#include <stdio.h>
#include <math.h>
int main(void)
{
int repeat;
double y;

scanf("%d", &repeat);

if(repeat>=0)
{
y=sqrt(repeat);
}
else
{
y=pow((1+repeat),2)+2*repeat+1.0/repeat;
}

printf("f(%d) = %0.2f\n", repeat, y);

return 0;
}