Last active
May 8, 2023 19:02
-
-
Save stevebauman/5882c13a83bce154d4abb2717b67822b to your computer and use it in GitHub Desktop.
Find Quadratic Roots Challenge
This file contains 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 | |
/** | |
* @return array An array of two elements containing roots in any order | |
* @link https://www.testdome.com/questions/php/quadratic-equation/38497 | |
*/ | |
function findRoots($a, $b, $c) | |
{ | |
return [ | |
(-$b + sqrt(pow($b, 2) - ((4 * $a) * $c))) / (2 * $a), | |
(-$b - sqrt(pow($b, 2) - ((4 * $a) * $c))) / (2 * $a), | |
]; | |
} | |
// Array | |
// ( | |
// [0] => -1 | |
// [1] => -4 | |
// ) | |
print_r(findRoots(2, 10, 8)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment