0% found this document useful (0 votes)
30 views2 pages

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

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
We take content rights seriously. If you suspect this is your content, claim it here.
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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy