commit existing workshops

This commit is contained in:
boris
2024-10-17 00:35:53 +01:00
parent 4070dc5367
commit ed02b435fe
74 changed files with 1083 additions and 91 deletions

33
workshop3/Operators/index.php Executable file
View File

@@ -0,0 +1,33 @@
<?php
$temp = array(78, 60, 62, 68, 71, 68, 73, 85, 66, 64, 76, 63, 75, 76, 73, 68, 62, 73, 72, 65, 74, 62, 62, 65, 64, 68, 73, 75, 79, 73);
function smallestTemp($temp)
{
sort($temp, SORT_NATURAL);
for ($i = 0; $i < 7; $i++) {
$smallestTemp[$i] = $temp[$i];
}
return implode(", ", $smallestTemp);
}
function largestTemp($temp) {
rsort($temp, SORT_NATURAL);
for ($i = 0; $i < 7; $i++) {
$largestTemp[$i] = $temp[$i];
}
return implode(", ", $largestTemp);
}
function calcAvgTemp($temp) {
$totalTemp = 0;
foreach ($temp as $value) {
$totalTemp += $value;
}
return round( ($totalTemp / count($temp) ), 1 );
}
echo "Average Temperature is : " . calcAvgTemp($temp);
echo "<br>";
echo "List of seven lowest temperatures : " . smallestTemp($temp);
echo "<br>";
echo "List of seven highest temperatures : " . largestTemp($temp);