Of course we're not gonna do this, unless you pay me $20.00 dollars for this problem.
But to start you off, this is the quadratic equation :
x = -b/(2a) +- sqrt(b^2 - 4ac) / (2a).
Since they gave you a,b, and c. You just have to plug it in though.
A word of caution this part of the equation b^2 - 4ac is called the discriminant. Make sure this is positive else the solution is imaginary.
firstPerson
Industrious Poster
4,044 posts since Dec 2008
Reputation Points: 851
Solved Threads: 625
Skill Endorsements: 15
Your problem is assuming that x1 and x2 are integers when you print them out.
Additionally, a,b,c are all likely to be floating point numbers. So read them in as floats. So make your output statement printf("%g and %g\n",x1,x2); Also you can use the sqrt function in line k=sqrt(d); .
HOWEVER: Can I just point out that using the formula given is a horrible way to calculate the roots to a quadratic equation due to the numeric instability of the solution. The "better" way is to calculate x1,x2 and determine which biggest root
(either in terms of magnitude or accuracy as a solution) and use the relationship x1*x2=c/a to get the other root.
There are further tricks to getting better roots from a quadratic equation, particularly if the roots are close, if b^2-4ac is near zero ,e.g a Newton Raphson step etc.
Finally, please use code tags.
StuXYZ
Practically a Master Poster
681 posts since Nov 2008
Reputation Points: 760
Solved Threads: 138
Skill Endorsements: 0
@moseshenry
That's not what this forum for... You should read the forum rules before you post the code like that...
Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17