Solving the equation JavaScript

let readline = require("readline-sync");
// imports input module
console.log ( "Enter a:");
// print displaying a first number of input
var a = parseFloat(readline.question(""));
// declare variables cast string a =
console.log ( "Enter b:");
// print the display of the second number of input
var b = parseFloat(readline.question(""));
// declare variables cast string b =
console.log ( "Please enter c:");
// print displaying a third number of input data
var c = parseFloat(readline.question(""));
// declare variables c = cast to string
There delta = b * b - 4 * a * c;
// Declare Variable declare a variable delat = b b Save by 4 by a variable declaration by declaration of variables c
if(!isNaN(a) && !isNaN(b) && !isNaN(c))
// condition (with a non-non-non-b and c)
{
if (a==0)
// The above condition is satisfied is determined a == 0
{
console.log ( "you entered is not a quadratic equation");
// meets the above criteria is not a quadratic equation as you enter the show
}
else{
if(delta < 0)
// satisfy the above condition This condition is performed is smaller than 0 is determined delta
{
the console.log ( "Equation no real roots");
// the above conditions are met for this equation shows no real roots
}
else if(delta > 0)
// satisfy the above conditions is determined whether this condition is performed delta is greater than 0
{
var x1 = (-b + Math.sqrt(delta))/(a*2);
// This condition satisfies the above condition, if a delta> 0, the equation has two real roots of different execution x1
var x2 = (-b - Math.sqrt(delta))/(a*2);
// This condition satisfies the above condition, if a delta> 0, the equation has two real roots of different execution x2
console.log ( "This equation has two real roots are not identical: x1 =" + x1 + ", x2 =" + x2)
// print displays two different real roots of the equation for this purpose ...
}
else{
console.log ( "This same equation has two real roots: x1 = x2 =" + -b / 2 * a)
// print displays two different real roots of the equation for this purpose ...
}
}
}
else{
console.log ( "you entered is not correct!");
// do not meet all the conditions above are not displayed correctly when you enter
}

Guess you like

Origin www.cnblogs.com/fatingGoodboy/p/11386735.html