C Example: Quadratic Solver: discriminant, double root and degenerate cases
Solves ax²+bx+c=0 by discriminant: two real roots when D>0, a double root when D=0, no real roots when D<0; also handles a=0 linear and a=b=0 degenerate cases. Square root uses a self-contained Newton iteration, avoiding libm so the single file compiles directly.
🖥 Run OnlineGCC 10.2 · C11 standard · click ▶ to run · Copy code
🖨 Reference OutputMatches the online run in a standard C11 environment
a=1 b=-3 c=2 -> two roots: x1=1 x2=2 a=1 b=-2 c=1 -> double root: x=1 a=1 b=2 c=5 -> no real roots (discriminant=-16) a=0 b=2 c=4 -> linear: x = -2 a=0 b=0 c=0 -> all values are roots
🧩 Keep Learning