Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Write the algorithm using a flow chart and the algorithm description for calculating the root of a quadratic equation.

Thanks for your ideas!
Posted
Updated 13-Sep-12 0:55am
v2
Comments
AmitGajjar 13-Sep-12 6:45am    
What you have done so far ?

What you have tried so far.? This seems like school or university assignment, assume that your teacher or lecturer is also reading these forums.

You should try something by your side first and then post question if you get stuck somewhere. You MUST try here[^] first.

Also refer How to ask a good question?[^]
 
Share this answer
 
Starting with:

ax2 + bx + c = 0

the two possible roots are given by

x1 = (-b + (b2 - 4ac)0.5) / 2a

x2 = (-b - (b2 - 4ac)0.5) / 2a

Depending on the domain in which the solution can lie, you might have to check the discriminant for being smaller than 0. The discriminant is the part inside the square root: b2 - 4ac.
If the domain of the solution are the real numbers R then the discriminant being less than zero will mean that there is no solution. Should the domain be in the set of complex numbers C a solution will exist even if the discriminant is less than zero:

x1 = -b/2a + J(|b2 - 4ac|)0.5/2a
x2 = -b/2a - J(|b2 - 4ac|)0.5/2a

Solutions of quadratic equations are always complex conjugates of each other when the discriminant is smaller than zero.

Should the discriminant be zero x1 = x2 = -b / 2a there is only one solution.

Now all that is left to do is input the coefficients a,b,c and do the calculations.
I don't think you'll find that too hard to do. Just give it a try!

Regards,

— Manfred
 
Share this answer
 
v4
Comments
__TR__ 13-Sep-12 7:34am    
My 5 for the explanation and for adding "Thanks for your ideas!" to the OP's question :)
If you know how to solve it manually (you know that, right?) then you have the algorithm.
 
Share this answer
 
see below link.
Link 1[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900