1 1 1 2 21 2 3 321 6 n nn1

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: * (23 *(23*(23*(23*(529)))))= 23 * (23 *(23*(23*(12,167))))= 23 * (23 *(23*(279,841)))= 23 * (23 *(6,436,343))= 23 * (148,035,889)= 3,404,825,447 Factorial • For example, we would like to write a recursive func5on that computes the factorial of an Integer: 0! = 1 1! = 1 2! = 2*1 = 2 3! = 3*2*1 = 6 n! = n*(n ­1) * … *3*2* 1 2! = 2*1! 3! = 3*2! n! = n*(n ­1)! • The last observa5on, together with the simple cases is the basis for a recursive func5on. 8 Recursive Func,ons – Factorial Example # Return the factorial of the given int. def factorial(an_int) : if (an_int <= 0): return 1 else: return an_int * factorial(an_int – 1) • What happens if we make the func5on call factorial(4)?   What func5ons are called?   When does each func5on call return? 9 3 13 ­11 ­04 Calling Recursive Func,ons •...
View Full Document

This document was uploaded on 03/02/2014.

Ask a homework question - tutors are online