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
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.
  • Loading branch information
Roybas2001 committed May 2, 2023
1 parent 7a1294f commit 6cca007
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 6cca007

Please sign in to comment.