double型的数据输入必须用格式符"%lf",输出时可以用"%lf",也可以用%f。
printf("f(%.2f)=%.2\n",x,sqrt(x));这一句中少了个f,应为%.2f。
/*
Enter x : 12
f(12.00) = 3.46
Press any key to continue
*/
#include
#include
void main() {
double x;
printf("Enter x : ");
scanf("%lf",&x);
if(x < 0) printf("f(%.2lf) = %.2lf\n",x,pow((x + 1),2) + 2 * x + 1/x);
else printf("f(%.2lf) = %.2lf\n",x,sqrt(x));
}