zzuli OJ 1035: piecewise function evaluation

Description Title
is known: y is a function of x,
when x <-2, y = 7-2x;
when x> = - 2, and of x <3, y = 5- | 3x + 2 |;
when x> when = 3, y = 3x + 4

Enter
any input integer x.

Output
output as an integer, i.e., the function value corresponding to x.

Input Sample
2
Sample Output
-3

#include<stdio.h>
#include<math.h>
int main()
{
int a,b;
 scanf("%d",&a);
if(a<-2) b=7-2*a;
if(a>=-2&&a<3) b=5-fabs(3*a+2);
if(a>=3) b=3*a+4;
printf("%d",b);
return 0;
}
Published 96 original articles · won praise 22 · views 40000 +

Guess you like

Origin blog.csdn.net/weixin_43751787/article/details/85318400