diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..09605220 Binary files /dev/null and b/.DS_Store differ diff --git a/2022-Oct/.DS_Store b/2022-Oct/.DS_Store new file mode 100644 index 00000000..a80cb9f3 Binary files /dev/null and b/2022-Oct/.DS_Store differ diff --git a/2022-Oct/24 Oct 2022/index.js b/2022-Oct/24 Oct 2022/index.js new file mode 100644 index 00000000..856f2aa8 --- /dev/null +++ b/2022-Oct/24 Oct 2022/index.js @@ -0,0 +1,38 @@ +// program to solve quadratic equation +let root1, root2; + +// take input from the user +let a = prompt("Enter the first number: "); +let b = prompt("Enter the second number: "); +let c = prompt("Enter the third number: "); + +// calculate discriminant +let discriminant = b * b - 4 * a * c; + +// condition for real and different roots +if (discriminant > 0) { + root1 = (-b + Math.sqrt(discriminant)) / (2 * a); + root2 = (-b - Math.sqrt(discriminant)) / (2 * a); + + // result + console.log(`The roots of quadratic equation are ${root1} and ${root2}`); +} + +// condition for real and equal roots +else if (discriminant == 0) { + root1 = root2 = -b / (2 * a); + + // result + console.log(`The roots of quadratic equation are ${root1} and ${root2}`); +} + +// if roots are not real +else { + let realPart = (-b / (2 * a)).toFixed(2); + let imagPart = (Math.sqrt(-discriminant) / (2 * a)).toFixed(2); + + // result + console.log( + `The roots of quadratic equation are ${realPart} + ${imagPart}i and ${realPart} - ${imagPart}i` + ); +}