Previous Next
0 / 20
Module DEMO-32-89DEMO-C-32

Quadratic Equation Positive Root

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Calculate the positive root of a quadratic equation ax^2 + bx + c = 0.

Formula: (-b + sqrt(b^2 - 4ac)) / (2a).

Target difficulty: Medium

Constraints

b^2 - 4ac >= 0, a != 0

Input Format

Three floating-point numbers a b c.

Output Format

The positive root formatted to 2 decimal places.

Sample Testcases

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

Sample #1
Public sample
1 -3 2
2.00
(-(-3.0) + sqrt(-3.0^2 - 41.02.0)) / (2*1.0) = 2.00
Sample #2
Public sample
1 2 1
-1.00
(-(2.0) + sqrt(2.0^2 - 41.01.0)) / (2*1.0) = -1.00
Sample #3
Public sample
1 -7 12
4.00
(-(-7.0) + sqrt(-7.0^2 - 41.012.0)) / (2*1.0) = 4.00
Sample #4
Public sample
1 0 -9
3.00
(-(0.0) + sqrt(0.0^2 - 41.0-9.0)) / (2*1.0) = 3.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