← Back

Code Challenge 2.2 - Quadratic Equation


Introduction

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 a2 + bx + c = 0.

Quadratic Equation

Skills to Practice

Challenge Tasks

Sample Output

Sample 1: two real roots

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 2: one real root

Enter the coefficient a: 1 [Enter]
Enter the coefficient b: 2 [Enter]
Enter the coefficient c: 1 [Enter]
The root of the equation is: -1.

Sample 3: no real roots

Enter the coefficient a: 1 [Enter]
Enter the coefficient b: 2 [Enter]
Enter the coefficient c: 5 [Enter]
There are no real roots.