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

Computer Language Lecture 28

The document describes recursive functions for calculating factorials. It provides the mathematical formulas for calculating factorials of different numbers like 5!, 4!, etc. It then shows a recursive function in code that calculates the factorial of a given number n by checking if n is 1, in which case it returns n, or else it returns n multiplied by the factorial of n-1.

Uploaded by

Azhar Hussain
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Computer Language Lecture 28

The document describes recursive functions for calculating factorials. It provides the mathematical formulas for calculating factorials of different numbers like 5!, 4!, etc. It then shows a recursive function in code that calculates the factorial of a given number n by checking if n is 1, in which case it returns n, or else it returns n multiplied by the factorial of n-1.

Uploaded by

Azhar Hussain
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Recursive Functions: Factorial

n! = n * (n-1) * (n-2) …….. 3 * 2 * 1

5! = 5 * 4 * 3 * 2 * 1
4! = 4 * 3 * 2 * 1
5! = 5 * 4!
0! = 1
Recursive Functions: Factorial

long factorial ( long n )


{
if (n == 1 )
return ( n ) ;
else
return ( n * factorial (n-1) ) ;
}

You might also like