Using Recursive Function



Help for C/C++ for MVS, OS/390 C/C++, z/OS C/C++ and C/C++ Productivity Tools for OS/390

Re: Using Recursive Function

Postby dick scherrer » Thu Jul 01, 2010 9:33 am

Hello and welcome to the forum,

Suggest you look at the code Sabreen Khan has provided and make changes to this code to do what you want. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Using Recursive Function

Postby enrico-sorichetti » Thu Jul 01, 2010 8:18 pm

for the fibonacci series a truly recursive implementation would be
unsigned int fib(unsigned int n)
{
    return n < 2 ? n : fib(n-1) + fib(n-2);
}
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3003
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Previous

Return to C, C++

 


  • Related topics
    Replies
    Views
    Last post