Re: Recursive Functions
From: James Hu (jxh_at_despammed.com)
Date: 10/27/03
- Next message: Eric Sosman: "Re: Recursive Functions"
- Previous message: Sheldon Simms: "Re: Recursive Functions"
- In reply to: dmattis: "Recursive Functions"
- Next in thread: Glen Herrmannsfeldt: "Re: Recursive Functions"
- Reply: Glen Herrmannsfeldt: "Re: Recursive Functions"
- Reply: James Hu: "Re: Recursive Functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 27 Oct 2003 12:34:19 -0600
On 2003-10-27, dmattis <dmattis@yahoo.com> wrote:
> I am trying to write a recursive version of Power(x,n) that works by
> breaking n down into halves(where half of n=n/2), squaring
> Power(x,n/2), and multiplying by x again if n was odd, and to find a
> suitable base case to stop the recursion. Can someone give me an
> example of this?
This is not a C question... but the C answer is use pow() (unless you
are purposefully avoiding floating point, in which case a table lookup
is in order).
<DYOHW> Rewrite your word problem into a recurrence relationship. Use
induction to prove this recurrence correctly calculates x to the nth
power. It should be obvious at that point what your function should
look like and what your base case is. </DYOHW>
-- James
- Next message: Eric Sosman: "Re: Recursive Functions"
- Previous message: Sheldon Simms: "Re: Recursive Functions"
- In reply to: dmattis: "Recursive Functions"
- Next in thread: Glen Herrmannsfeldt: "Re: Recursive Functions"
- Reply: Glen Herrmannsfeldt: "Re: Recursive Functions"
- Reply: James Hu: "Re: Recursive Functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|