[Tutor] recursion question

Gregor Lingl glingl at aon.at
Tue Dec 2 18:45:34 EST 2003



Matt Richardson schrieb:

>It's been awhile since I've posted last, but I promise I've been a
>faithful lurker :)  Actually, it's been awhile since I've had a chance
>to work with python, so it feels kinda good to ask a question.
>
>I've been taking a c++ class this term and found it to be not as
>...
>  
>
>>>>def mult(m, n):
>>>>        
>>>>
>	if n == 0:
>		return 0
>	if n == 1:
>		return m
>	return m + mult(m, n-1)
>
>  
>
>>>>mult(5, 5)
>>>>        
>>>>
>25
>
>Ok, maybe it's just me thinking about it too much, or not enough, but
>I'm just not quite getting how these work. 
>
Hi Matt!
There is an excellent chapter (# 4) on recursion in this online-tutorial:

http://www.ibiblio.org/obp/thinkCSpy/

The same also exists in a c++ version:

http://www.ibiblio.org/obp/thinkCS/cpp/english/

Regards,
Gregor





More information about the Tutor mailing list