0% found this document useful (0 votes)
46 views

Recursive Functions

Recursive functions are functions that call themselves. The example provided calculates the factorial of a number recursively by having the function call itself with decreasing arguments until it reaches 1, at which point it returns the argument and the successive function calls multiply the returns together to calculate the factorial. The output displays that the factorial of 4, calculated by the recursive function, is 24.

Uploaded by

rina mahure
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Recursive Functions

Recursive functions are functions that call themselves. The example provided calculates the factorial of a number recursively by having the function call itself with decreasing arguments until it reaches 1, at which point it returns the argument and the successive function calls multiply the returns together to calculate the factorial. The output displays that the factorial of 4, calculated by the recursive function, is 24.

Uploaded by

rina mahure
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Recursive Functions:

Recursion refers to a situation, wherein functions call themselves. In other words, there is a call
to a specific function from within the same function. Such functions are known as Recursive
Functions.

Example:
<html>
<head><title></title>
<script language="javascript">
function fun1(number)
{
if(number>1)
{
return number*fun1(number-1)
}
else
{
return number
}
}
var a
a=fun1(4)
document.write("The factorial of a number is "+a)
</script>
</body>
</body>
</html>

Output:
The factorial of a number is 24

You might also like