Re: Recursion

new topic     » goto parent     » topic index » view thread      » older message » newer message

don cole wrote:

  
>  -- this is iteration
>  --this is recursion
> 
> Is this correct?

Yes, but not something that people might actually do.

This is iteration :

   function facti(int n)
      int res
      res = 1
      for i = 2 to n do
          res *= i
      end for
      return res
   end function

This is recursion :

   function factr(int n)
      if n <= 1 then
         return 1
      end if
      return n * factr(n-1)
   end function


-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu