Answer the question
In order to leave comments, you need to log in
How to find the minimum and maximum of three variables without the min and max functions?
It is necessary to determine the sum of the maximum and minimum of the three numbers $a, $b, $c.
NOT APPLYING THE FUNCTIONS min and max.
With functions, I know how to do it. And without them, how to write code to determine the sum of the maximum and minimum of the three numbers $a, $b, $c.
Thank you.
Or throw where such examples are considered.
Answer the question
In order to leave comments, you need to log in
$sum = $a > $b ? ($a > $c ? $a + ($b < $c ? $b : $c) : $b + $c) : ($b > $c ? $b + ($a < $c ? $a : $c) : $c + $a);
$numbers = [$a, $b, $c];
sort($numbers);
echo reset($numbers) + end($numbers);
function sumMinMax(...$numbers)
{
$min = PHP_INT_MAX;
$max = 0;
foreach ($numbers as $key => $number) {
if ($number > $max)
$max = $number;
if ($number < $min)
$min = $number;
}
return $min + $max;
}
$a = 1;
$b = 2;
$c = 3;
$d = 4;
$e = 5;
$f = 6;
echo sumMinMax($a,$b,$c,$d,$e,$f);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question