哪里不对吗?分段了,还保留两位了5434513843786
#include<math.h>
{
float x;
scanf("%1f", &x);
if(x>=0){
f(x)=sqrt(x);
}else if(x<0){
f(x)=pow(x+1,2)+2x+1/x;
}
printf("f(x)=f(%.2f) = %.2f",x);
return 0;
}
#include<math.h>
{
float x;
scanf("%1f", &x);
if(x>=0){
f(x)=sqrt(x);
}else if(x<0){
f(x)=pow(x+1,2)+2x+1/x;
}
printf("f(x)=f(%.2f) = %.2f",x);
return 0;
}
修改如下,改动处见注释,供参考:
#include<stdio.h> // 修改
#include<math.h>
int main() // 修改
{
float x, result; // 修改
scanf("%f", &x);//scanf("%1f", &x); 修改
if(x>=0){
result = sqrt(x);//f(x)=sqrt(x); 修改
}else if(x<0){
result = pow(x+1,2)+2*x+1.0/x; //f(x)=pow(x+1,2)+2x+1/x; 修改
}
printf("f(%.2f) = %.2f", x, result); //printf("f(x)=f(%.2f) = %.2f",x); 修改
return 0;
}