Jensen's Device: Difference between revisions
Content added Content deleted
(added php) |
|||
Line 221: | Line 221: | ||
print sum($i, 1, 100, sub { 1 / $i }), "\n";</perl> |
print sum($i, 1, 100, sub { 1 / $i }), "\n";</perl> |
||
Output: 5.18737751763962 |
Output: 5.18737751763962 |
||
=={{header|PHP}}== |
|||
<php>$i; |
|||
function sum (&$i, $lo, $hi, $term) { |
|||
$temp = 0; |
|||
for ($i = $lo; $i <= $hi; $i++) { |
|||
$temp += $term(); |
|||
} |
|||
return $temp; |
|||
} |
|||
echo sum($i, 1, 100, create_function('', 'global $i; return 1 / $i;')), "\n";</php> |
|||
Output: 5.18737751764 |
|||
=={{header|Python}}== |
=={{header|Python}}== |