Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Commit

Permalink
Create find_roots_of_quadratic_equation.php (#7506)
Browse files Browse the repository at this point in the history
Find roots of quadratic equation in php, comment in the code of what everything does.

Co-authored-by: Kartikeya Saini <111000515+hi-Kartik2004@users.noreply.github.com>
  • Loading branch information
Roybas2001 and hi-Kartik2004 committed May 5, 2023
1 parent bb009a5 commit f6d7b01
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
// Give the input values for the formula
$inputA = 5;
$inputB = 10;
$inputC = 2;

// $sumD is the part of the equation that is inside of the square root
$sumD = pow($inputB, 2) - 4 * $inputA * $inputC;

// The rest of the equation. Everything is put in () so it is calculated in the right order.
$outputPositive = (-$inputB + pow($sumD, 0.5)) / (2 * $inputA);
$outputNegative = (-$inputB - pow($sumD, 0.5)) / (2 * $inputA);

echo "x = $outputPositive &nbsp; or &nbsp; x = $outputNegative";

0 comments on commit f6d7b01

Please sign in to comment.