Quadratic equation solver program
In this article will be looking at how to build a quadratic equation solver program.
We'll be building the Algorithm first and then followed by choosing a program which we are comfortable with to run the the the program.
What is an Algorithm
An algorithm is a step-by-step instruction written to solve a given problem.
It is recommended to write an algorithm before writing the main code for some of the advantages is that it helps to visualise the steps that will be required for the program to work perfectly and efficiently and it makes the the work of a programmer faster.
Algorithm to solve Quadratic Equation
1. Start
2. Input a, b, c
3. d = (b*b) - 4*a*c
4. root1 = -b/(2*a) + sqrt(-d)/(2*a)
5. root2 = -b/(2*a) - sqrt(-d)/(2*a)
6. If(d < 0)
6.1 Output "The roots of the equation are complex numbers which are: \n"
6.2 Output root1, root2
7. Else if(d == 0)
7.1 root = -b/(2*a)
7.2 Output "The roots of the equation are equal which is: "
7.3. Output root
8. Else
8.1 Output "The roots of the equation are real numbers which are: \n"
8.2 Output root1, root2
9. Stop
You can find the code sample written in JavaScript here