题目描述
已知:y 是 x 的函数,
当 x<-2 时,y=7-2x;
当 x>=-2,且 x<3 时,y=5-|3x+2|;
当 x>=3 时,y=3x+4
输入描述
任意输入一个整数 x。
输出描述
输出为一个整数,即 x 对应的函数值。
输入样例
2
输出样例
-3
提示
- abs 函数在 <stdlib.h> 头文件中
- fabs 函数在 <math.h> 头文件中
- abs 函数的参数和返回值都是 int 类型
- fabs 函数的参数可以是 float 、 double 等浮点数类型,返回值为 double 类型
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int x;
scanf("%d",&x);
if(x<-2)
printf("%d\n",7-2*x);
else
if(x>=-2&&x<3)
printf("%d\n",5-abs(3*x+2));
else
if(x>=3)
printf("%d\n",3*x+4);
return 0;
}