Created
November 7, 2020 13:10
-
-
Save dan0nchik/0ff37b0fa53a85e38d5e9f4eb94a6e3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function equation($a, $b, $c){ | |
if ($a != 0){ | |
$D = $b*$b - 4*$a*$c; | |
if($D < 0){ | |
return "No roots"; | |
} | |
if($D == 0){ | |
return -$b/(2*$a); | |
} | |
if($D > 0) { | |
$x1 = (-$b + sqrt($D)) / (2*$a); | |
$x2 = (-$b - sqrt($D)) / (2*$a); | |
return array($x1, $x2); | |
} | |
} | |
else{ | |
if($b==0) return "No roots"; | |
return -$c*$b; | |
} | |
} | |
$res = equation(6,0,0); | |
if(gettype($res) == "array"){ | |
foreach ($res as $i) echo "Root: ".$i."</br>"; | |
} | |
else print $res; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment