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)