C语言高手来,编写一函数,求:f(x)=x^2+1,x>1 ;f(x)=x^2,-1<=x<=1;f(x)=x^2-1,x<-1.
C语言高手来,编写一函数,求:f(x)=x^2+1,x>1 ;f(x)=x^2,-1<=x<=1;f(x)=x^2-1,x<-1.
日期:2011-03-30 15:35:05 人气:1
楼上的有错误,正确的如下:
#include
void main()
{
double x,y;
scanf("%lf",&x);
if(x>1)
y=x*x+1;
if(x>=-1&&x<=1)
y=x*x;
if(x<-1)
y=x*x-1;
printf("%lf",y);
}