|
-
Jan 9th, 2002, 05:29 AM
#1
Thread Starter
Frenzied Member
Fibonacci Recurision in C/C++
I have written a program in C/C++ solving the fibonacci series using recursion. Can anyone tell me if this is a fast way of doing it. l kown that memory can run out each time is calls the recursive function and does not return it until it returns. But is there any advantages by doing it this way, and what are the disadvantages of doing it this way. Would C or C++ perform the same.
Many Thanks in Advance
-
Jan 9th, 2002, 06:19 AM
#2
transcendental analytic
Yes, no, the disadvantages are obvious, each recursion needs stack space and a function call, so both performance and memory usage. Go for iterative solution.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jan 9th, 2002, 08:56 AM
#3
I did it once too. It nearly killed my computer when I ran it:
for(int i = 50; i > 0; i--)
{
printf("%i",Fib(i));
}
It took the computer (600 MHz) about 10 seconds for each iteration...
Anyway, C and C++ should behave exactly the same in this case.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|