Search⌘ K

Example 10: Solve the Quadratic Equation

Explore solving quadratic equations using decision-making structures in C. Understand how to calculate the discriminant to determine root existence and compute roots when they are real. This lesson equips you to handle conditional logic and mathematical operations for quadratic solutions in your programs.

We'll cover the following...

Problem

A quadratic equation is an equation of this form:

ax2+bx+c=0ax^{2}+bx+c=0

Given the values of the coefficients a, b, and c, you need to find the corresponding quadratic equation solution.

The following output needs to be printed on the console:

  • Roots (if any)
  • No real roots (if no roots)

Example

Input (a, b, c) Output
1, 5, 6 -2.000000 , -3.000000
1, 2, 3 No real roots

Try it yourself

...