From f2a09f02da4bceb900af864e9088d96e15d4d1b4 Mon Sep 17 00:00:00 2001 From: Avinash kumar <49323775+Avinashluhana@users.noreply.github.com> Date: Mon, 24 Oct 2022 17:18:05 +0500 Subject: [PATCH] added a js program --- .DS_Store | Bin 0 -> 6148 bytes 2022-Oct/.DS_Store | Bin 0 -> 8196 bytes 2022-Oct/24 Oct 2022/index.js | 38 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 .DS_Store create mode 100644 2022-Oct/.DS_Store create mode 100644 2022-Oct/24 Oct 2022/index.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..096052200a9ce03ad492e8c3d57c6eed60f9313d GIT binary patch literal 6148 zcmeHKO^?$s5FK~BtfLiD4~Be>|53dnO&fA z*SJMb>4d7sg+1A-mc-wv06#lTJ?g-FwDJ7X!loGGh4B!6_{|xj3+mJ5d>ZP%q|+jw zSDnsR)!1q7UfI)odSAaz-q~eRjjP3cFrK~S-ZN{9^ei5y&-2N0)VlV_men{fCo@OL zvk6LGy~xYVE(dl|W^>0){D6*hG-@5JR^5KTZTk1R>$X|l?{(VdPXF$D9qH>gZ$CI5 zy)RBn`_cV!Qdpj!X!j^9_#=K}lr-UXn^(%ctsn4j|R4SrlI)Z*f zdICJ8Q_A?i@spu${K7z2OcW3WM1f0JAiN9p{-w_(6Nmz$z`v#dzaI>oF%DRJbgvFH z?g#*EBJB(@e=;)11dIdL9x(z_o(l9-6^1 mJ^r8|a9c5Ic`H7EJ44=Z0E`3H9+82`hk%no8d2bnD)1d>6>gdU literal 0 HcmV?d00001 diff --git a/2022-Oct/.DS_Store b/2022-Oct/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a80cb9f3739d2d67e7ddaeed6681f4f8c04c9e9b GIT binary patch literal 8196 zcmeI1zfQw25XR4?L#0ZH33UNwU`8bT-$GReCM3Etpte#O(xyVd9Ep*Qg^gF>C3q<& z`0i|wlDKkNC=z$l`HK>Nb^CK2_fjG<-Mdjt)FGl4l69?(#uI#DEQbP$S0VSXWlz)zQ)55CUI?zZ70Bz#5 z1ddS$h$nKIIxVb<6|ZTl2ji^9l^Dj_aXsSh(9~&R)!NBeI~g~!aTSV@(cz1vJDJp~ zwn{(=)Cq9y-bTG1W4)c1>i6U<%ZGz3AD{;>suSe)hXjtSD+#(@J+9r5%WQaDdqLNu z$F(1Hy?a~-Ay;GUaUF(S!tkZS@F?hFhE>;b$R!NRt~fl)h8b2}!C5xUu<8oVvM{W= zg7d`;&1#8ZOu_jgFs!+PqGKZ9U-rf9Ne$4Di$=dn?t1>hkpNI ah~o%d*^@dgtl|tpe+UQ$ZIr;T68Hqv$p>!$ literal 0 HcmV?d00001 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` + ); +}