Created
June 3, 2012 23:06
-
-
Save DrStrangeLove/2865350 to your computer and use it in GitHub Desktop.
Quadratic Equation Solver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function quadraticEquation(ar){ | |
var d; | |
d = Math.pow(ar[1],2)-(4*ar[0]*ar[2]); | |
if (d<0){ | |
alert("No Solutions!!"); | |
} else if (d>0){ | |
var res1 = (- (ar[1])- Math.sqrt(d))/(2*ar[0]); | |
var res2 = (- (ar[1])+ Math.sqrt(d))/(2*ar[0]); | |
var o = {}; | |
o["x1"] = res1; | |
o["x2"] = res2; | |
alert(JSON.stringify(o)); | |
} | |
if (d===0){ | |
var res = (- (ar[1]))/(2*ar[0]); | |
alert(res); | |
} | |
} | |
quadraticEquation([8,-14,5]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment