C语言中求解表达式的程序。要编写出程序啊`~~帮忙!

来源:百度知道 编辑:UC知道 时间:2024/05/29 00:55:22
求分段函数y=f(x)的值,其中f(x)的表达式如下:
x*x-1 (x<-1)
f(x)= x*x (-1<=x<=1)
x*x+1

#include<stdio.h>
main(){
double x;
scanf("%lf",&x);
if(x<-1)
printf("%lf",x^2-1);
else if(x>=-1&&x<=1)
printf("%lf",x^2);
else if(x>1)
printf("lf",x^2+1);
}

#include<iostream>
using namespace std;

int main()
{
double x;
cout << "Please input x: ";//输入x的值
cin >> x;
if(x < -1)
{
cout << "The result is: " << x*x-1 << endl;
}
else if(x > 1)
{
cout << "The result is: " << x*x << endl;
}
else
{
cout << "The result is: " << x*x+1 << endl;
}
return 0;
}

#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
double x;

cout << "Please input x: "