1034. Find Roots of a Quadratic Equation

You are given three real numbers a, b, and c representing the coefficients of a quadratic equation:

ax² + bx + c = 0

Your task is to compute the two roots and return them as strings in a string array.

Example 1:

Input: a = 1, b = -3, c = -10

Output: ["-2.00", "5.00"]

Example 2:

Input: a = 1, b = 1, c = 1

Output: ["-0.50+i0.87", "-0.50-i0.87"]

Now Your Turn!

Pick the correct output for the given input

Input: a = 2, b = 4, c = 2

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • -1000 ≤ a, b, c ≤ 1000
  • a ≠ 0
0
class Solution {
public:
vector<string> findRoots(double a, double b, double c) {
}
};
Test Case

Input:

A
B
C