zzulioj 1035: Piecewise function evaluation

Title description
Known: y is a function of x,
when x<-2, y=7-2x;
when x>=-2, and x<3, y=5-|3x+2|;
when x> =3, y=3x+4
input
Any integer x can be input.
Output The
output is an integer, which is the function value corresponding to x.
Sample input Copy
2
Sample output Copy
-3

#include<stdio.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
	      printf("%d\n",3*x+4);
	return 0;
}

Guess you like

Origin blog.csdn.net/m0_53024529/article/details/112847197