Last active
December 19, 2015 09:58
-
-
Save krmgns/5936481 to your computer and use it in GitHub Desktop.
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 | |
function avg(){ | |
return array_sum(func_get_args()) / func_num_args(); | |
} | |
function avgr($a){ | |
return array_sum($a) / count($a); | |
} | |
function avg() { | |
$sum = 0; | |
$num = func_num_args(); | |
for($i = 0; $i < $num; $i++) { | |
$sum += func_get_arg($i); | |
} | |
$avg = $sum / $num; | |
return $avg; | |
} | |
function avgr($a) { | |
$sum = 0; | |
$num = count($a); | |
for($i = 0; $i < $num; $i++) { | |
$sum += $a[$i]; | |
} | |
$avg = $sum / $num; | |
return $avg; | |
} | |
printf("%.2f\n", avg(2,1,2,1,3,4,5,1,3,6)); | |
printf("%.2f\n", avgr(array(2,1,2,1,3,4,5,1,3,6))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment