PHP Menghitung Range

<?php
$bil = array (9, 2, 10, 3, 7, 5, 2);

$i = 0;
echo “Data aslinya<br>”;
while(list($indeks,$nilai)=each($bil))
{
echo “$nilai  “;
$i=$i+1;
}
echo “<br>”;

$min = $bil[0];
$max = $bil[0];
for ($i=0; $i<=count($bil)-1; $i++)
{
if ($bil[$i] < $min)
{
$min = $bil[$i];
}
else if ($bil[$i] > $max)
{
$max = $bil[$i];
}
}
echo “Nilai min =”.$min.”<br>”;
echo “Nilai max =”.$max.”<br>”;
$range=$max-$min;
echo “Rangenya adalah “.” = “.$range;
?>

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: