Recursion

[Total: 0    Average: 0/5]

This html file has a function “factorial” that uses recursion.

Body Code:

<script type=text/javascript>
function factorial(x) {
 if (x>1) return x * arguments.callee(x-1);
 else return 1;
}
document.write('Sample Invocation:')
document.write('factorial(10);')
document.write("<BR>This would result in the value ("+factorial(10)+") being returned by the function.");
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *