Briefly glancing over your answers, I see that your answer for Q19 is wrong:
<?php
function magic($p, $q)
{
return ($q == 0)
? $q
: magic($q, $p % $q);
}
?>
The answer is
d) Determines the greatest common divisor between them
Its called Euclid's Algorithm. Fairly standard (and useful) algorithm.
EDIT: Although, looking back, I sincerely hope that you transcribed this incorrectly, as it should be this:
<?php
function magic($p, $q)
{
return ($q == 0)
? $p # P not Q, otherwise it would always return 0
: magic($q, $p % $q);
}
?>
Stargazer712
2010-07-12 22:40:55