三:编程,输入x后,根据下式计算并输出y值。
#include<stdio.h> #include<math.h> void main () { double x,y; printf("输入x:"); scanf("%lf",&x); if(x<-2){ y=x*x; } else if(x>2){ y=sqrt(x*x+x+1); } if((x>=-2)&&(x<=2)){ y=2+x; } printf("y=f(%f)=%.2f\n",x,y); }
#include<stdio.h> #include<math.h> void main () { double x,y; printf("输入x:"); scanf("%lf",&x); if(x<-2){ y=x*x; } else if(x>2){ y=sqrt(x*x+x+1); } if((x>=-2)&&(x<=2)){ y=2+x; } printf("y=f(%f)=%.2f\n",x,y); }