Day 21: Quadratic Equation of 100DaysCodingChallenge
Hello all,
I have started the 100 days of coding challenge to improve my programming skills..
Today is the Day21 of 100DaysCodingChallenge for
Quadratic Equation taken inputs by the user.
Code :
let a = prompt("Enter a : "); let b = prompt("Enter b : "); let c = prompt("Enter c : "); let d = (b*b) - (4*a*c); if (d > 0) { console.log("The roots are real and different."); let root1 = (-b-Math.sqrt(d))/2*a; let root2 = (-b+Math.sqrt(d))/2*a; console.log("The real and different roots are : ", root1, root2); } else if (d == 0) { console.log("The roots are real and equal."); let root1 = root2 = -b/2*a; console.log("The real and equal roots are : ", root1, root2); } else { console.log("The roots are complex and different."); let realPart = -b/(2*a); let imaginaryPart = Math.sqrt(-d)/(2*a); console.log("root1 = ", realPart, "+", "i", imaginaryPart); console.log("root1 = ", realPart, "+", "i", imaginaryPart); }
Output :
Happy Coding:)
Comments
Post a Comment