解题思路:
注意事项:
参考代码:
#include<iostream> #include<cmath> using namespace std; double Absolute_value_function(double x); double Square_root_function(double x); double Exponential_function(double x); double First_order_function(double x); void output_function(double x); int main() { double x; cin>>x; if(x<0) output_function(Absolute_value_function(x)); else if(x>=0&&x<2) output_function(Square_root_function(x)); else if(x>=2&&x<4) output_function(Exponential_function(x)); else output_function(First_order_function(x)); } //尝试自己编写像fabs()函数。。。 double Absolute_value_function(double x) { return fabs(x); } double Square_root_function(double x) { double y=x+1; return sqrt(y); } double Exponential_function(double x) { double y=x+5; return pow(y,5); } double First_order_function(double x) { return 2*x+5; } void output_function(double x) { printf("%.2f",x); }
0.0分
0 人评分