Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 recursion problems
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
riveryu




PostPosted: Wed May 21, 2008 10:30 pm   Post subject: recursion problems

Hey ppl, I want to practice my recursion skills, if any of you have problems please post here...
This may not be just for me.
Yes, I googled it...
(am i in the right section here or should i post somewhere else?)

The ones I know are ones from the Recursion tutorial here at the forum except for...

1. factorials, which are positive integers which is the product of all the positive integers before it. (wikipedia says non-negative because 0 is a factorial of 0).
ex. 5 x 4 x 3 x 2 x 1 = 120, denoted as !5, with that exclaimation
write a program that finds the factorial of a given number using recursion

2. Squaring
write a program that can replace the n**e function in Turing, where as n is a real number and e is the exponent . using recursion
Thanks a lot.

Answers here... Highlight / select them with your mouse to see

Quote:
fcn square (number : real, exponent : real) : real
if exponent = 1 then
result number
else
result number * square (number, exponent - 1)
end if
end square
put square (2,2)

fcn fact (number : int) : int
if number = 1 then
result number
else
result number * fact (number - 1)
end if
end fact
put fact(5)
Sponsor
Sponsor
Sponsor
sponsor
r691175002




PostPosted: Wed May 21, 2008 10:46 pm   Post subject: Re: recursion problems

Fibonacci numbers, where each number is the sum of the previous two:
0 1 1 2 3 5 8 13...

Fibonacci numbers with memoization ( http://en.wikipedia.org/wiki/Memoization )

Something more advanced would be graph search problems such as depth first and breadth first searches.
riveryu




PostPosted: Thu May 22, 2008 11:12 am   Post subject: RE:recursion problems

hey, sry but that was already mentioned the Recursion Tutorial...all of what you said...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: