JavaScript program to solve a quadratic equation of the form ax^2 + bx + c = 0
:
let a = 1;
let b = -5;
let c = 6;
let discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
let x1 = (-b + Math.sqrt(discriminant)) / (2 * a);
let x2 = (-b - Math.sqrt(discriminant)) / (2 * a);
console.log("The solutions are " + x1 + " and " + x2);
} else if (discriminant === 0) {
let x = -b / (2 * a);
console.log("The solution is " + x);
} else {
console.log("The equation has no real solutions.");
}