Skip to content

Instantly share code, notes, and snippets.

View nipunTharuksha's full-sized avatar
🏠
Working from home

Nipun Tharuksha nipunTharuksha

🏠
Working from home
View GitHub Profile
@sedera-tax
sedera-tax / quadraticEquation.php
Created January 15, 2021 13:41
3. Quadratic Equation Implement the function findRoots to find the roots of the quadratic equation: ax2 + bx + c = 0. The function should return an array containing both roots in any order. If the equation has only one solution, the function should return that solution as both elements of the array. The equation will always have at least one sol…
<?php
/**
* @return array An array of two elements containing roots in any order
*/
function findRoots($a, $b, $c)
{
$delta = ($b * $b) - 4 * ($a * $c);
$x = (- $b - sqrt($delta)) / (2 * $a);
$y = (- $b + sqrt($delta)) / (2 * $a);
return [$x, $y];