divider

Objective

Your task is to create a program that solves quadratic equations using the quadratic formula. Given coefficients a, b, and c, your program should calculate the roots of the equation ax2 + bx + c = 0.

Skills to Practice

  • icon Invoking math functions for complex calculations
  • icon Branching with selection statements
divider

Tasks

  • icon Create a new project named application-2-2
  • icon Complete the following tasks:
    • icon Prompt the user to input the coefficients a, b, and c.
    • icon Calculate the discriminant b2 - 4ac.
    • icon Determine the roots of the equation based on the discriminant:
      • icon If the discriminant is positive, there are two distinct real roots.
      • icon If the discriminant is zero, there is one real root.
      • icon If the discriminant is negative, there are no real roots.
    • icon Display the roots in a clear format.
divider

Sample Output

Sample Output 1
Enter the coefficient a: 1 [Enter]
Enter the coefficient b: -3 [Enter]
Enter the coefficient c: 2 [Enter]
The roots of the equation are: 2 and 1.
Sample Output 2
Enter the coefficient a: 1 [Enter]
Enter the coefficient b: -3 [Enter]
Enter the coefficient c: 2 [Enter]
The roots of the equation are: 2 and 1.
Sample Output 3
Enter the coefficient a: 1 [Enter]
Enter the coefficient b: -3 [Enter]
Enter the coefficient c: 2 [Enter]
The roots of the equation are: 2 and 1.

Begin Challenge