Previous Next
0 / 6
Module DEMO-32-57DEMO-C-32

Piecewise Function Evaluator

DEMO-C-32 • Programming in C

Browser-only practice

Problem Statement

Problem Description

You are given a real number x. Your task is to evaluate the following piecewise function f(x):

  • Case 1: If x < -1, then f(x) = x² - 3x + 2
  • Case 2: If -1 ≤ x ≤ 3, then f(x) = 2x + 5
  • Case 3: If x > 3, then f(x) = x³ - 10

Based on the value of x, determine which case applies and compute the corresponding function value.

Examples

  • For input -2, the output is 12.00 (Case 1)
  • For input 4, the output is 54.00 (Case 3)
  • For input 0, the output is 5.00 (Case 2)

Constraints

The input x satisfies: -1000 ≤ x ≤ 1000

Input Format

A single line containing one real number x.

Output Format

Output the computed value of f(x) formatted to exactly two decimal places.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
-2
12.00
x = -2 falls in the first case (x < -1). f(-2) = (-2)² - 3(-2) + 2 = 4 + 6 + 2 = 12.00
Sample #2
Public sample
4
54.00
x = 4 falls in the third case (x > 3). f(4) = 4³ - 10 = 64 - 10 = 54.00
Sample #3
Public sample
0
5.00
x = 0, second case. f(0) = 2(0) + 5 = 5.00

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings