Previous Next
0 / 18
Module DEMO-32-90DEMO-C-32

Quadratic Root Finder

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a function float findRoot(float a, float b, float c) that returns the larger root of the quadratic equation ax^2 + bx + c = 0.

Assume real roots exist (discriminant >= 0).

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

Constraints

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

Input Format

Three floats a, b, c.

Output Format

The larger root.

Sample Testcases

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

Sample #1
Public sample
1.0 -3.0 2.0
2.000000
Roots are 1 and 2. Max is 2.
Sample #2
Public sample
2.0 0.0 -8.0
2.000000
2x^2 = 8 -> x^2=4 -> x=2 or -2. Max 2.
Sample #3
Public sample
1.0 -5.0 6.0
3.000000
Roots 2, 3. Max 3.

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