用if else if 判断即可
你题目的解答代码如下:
#include<iostream>
#include<cmath>
using namespace std;
double f(double x)
{
if (x<-10)
return 2 * x + 1;
else if (x>=-10 && x<=10)
return 3*pow(x,2) + pow(5,x) - 6;
else if (x>10)
return exp(x) + 2*pow(x,2) + 5;
}
int main()
{
double x;
cin >> x;
cout << f(x) << endl;
return 0;
}
如有帮助,望采纳!谢谢!
#include <iostream>
#include <cmath>
using namespace std;
double f(double x)
{
if (x < -10)
return 2 * x + 1;
else if (x <= 10)
return (3 * pow(x, 2) + pow(5, x) - 6);
else
return (exp(x) + 2* pow(x, 2) + 5);
}
int main(int argc, char const *argv[])
{
for (int i =-20; i < 20; i++)
{
cout << f(i);
}
}