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