Algorithm Analysis
To solve the problem, we will use a conditional statement.
Algorithm Implementation
Read the input value .
scanf("%d", &x);
Calculate the value .
if (x < -4) y = x + 5; else if (x <= 7) y = x * x - 3 * x; else y = x * x * x + 2 * x;
Print the result.
printf("%lld\n",y);
Java Implementation
import java.util.*; public class Main { public static void main(String[] args) { Scanner con = new Scanner(System.in); int y, x = con.nextInt(); if (x < -4) y = x + 5; else if (x <= 7) y = x * x - 3 * x; else y = x * x * x + 2 * x; System.out.println(y); con.close(); } }
Python Implementation
Read the input value .
x = int(input())
Calculate the value .
if x < -4: y = x + 5 elif x <= 7: y = x * x - 3 * x else: y = x * x * x + 2 * x
Print the result.
print(y)