<problem>
<script type="loncapa/perl">
sub fact {
my $n=shift;
if ($n==1) {
return $n;
} else {
return $n*&fact($n-1);
}
}
$testvalues='0=1';
foreach $i (1..3) {
$rand=&random(3,8,1);
$testvalues.=','.$rand.'='.&fact($rand);
}
</script>
<startouttext />Write a Perl subroutine called <tt>factorial</tt>, which returns the factorial of its argument, e.g. <tt>&factorial(17)=17!</tt>.
<instructorcomment>
Sample code for an evaluation script can be found <a href="/res/adm/includes/templates/sampleexternal.pl">here.</a></instructorcomment>
<endouttext />
<externalresponse url="http://localhost/cgi-bin/sampleexternal.pl" answer="$testvalues">
<textfield />
</externalresponse>
</problem>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>