How would a I make the loop so that it would keep generating it over nad over
Thanx in advance
This is a discussion on Fibonacci How should I make a generator within the C Programming forums, part of the General Programming Boards category; How would a I make the loop so that it would keep generating it over nad over Thanx in advance...
How would a I make the loop so that it would keep generating it over nad over
Thanx in advance
The world is waiting. I must leave you now.
Hey Cprog! Stop asking people here to do your homework for you.. hehe
the binary conversion was a bonus..
Homework question?
Ah, I'll help...a little I guess.
> How would a I make the loop so that it would keep generating it over nad over
While your terminology confuses me, I'll take it you want to create and endless loop.
Just create a loop that is based on a condition that will always be true.
The world is waiting. I must leave you now.
Look up the formula for calculating the nth term of the Fabonacci sequence and then use recursion.Originally posted by cprog
How would a I make the loop so that it would keep generating it over nad over
Thanx in advance
in the case of the fibonacci series, this is a horribly inefficient methodOriginally posted by MrWizard
Look up the formula for calculating the nth term of the Fabonacci sequence and then use recursion.
hello, internet!
Yep, very very inefficient.
>> How would a I make the loop so that it would keep generating it over nad over
Here's a hint:
Code:var1 var2 ----- ----- 0 1 1 2 3 5 8 13 etc...
Try not.
Do or do not.
There is no try.
- Master Yoda
>in the case of the fibonacci series, this is a horribly inefficient method
Only if you do it the icky way:
It may be cute, but the size of the recursive tree is ridiculous for small values of n. Better to use iteration or memoization to avoid continuous recalculation.Code:/* The icky way */ long fib ( int n ) { if ( n == 0 ) return 0; else if ( n == 1 ) return 1; else return fib ( n - 1 ) + fib ( n - 2 ); }
-Prelude
My best code is written with the delete key.
Or for the smiley challenged :
-PreludeCode:for ( ; ; ) or while ( 1 )
My best code is written with the delete key.
I believe if (n == 0) should return 1. The first two terms in the fibonacci sequence are 1, 1 right ? Anyways I know that way is pretty inefficient. The only reason I posted here is because I had an assignment to write the algorithm in assembly using recursion so I was just sharing one possible solution. I did not say it was efficient or the best.Originally posted by Prelude
>in the case of the fibonacci series, this is a horribly inefficient method
Only if you do it the icky way:
It may be cute, but the size of the recursive tree is ridiculous for small values of n. Better to use iteration or memoization to avoid continuous recalculation.Code:/* The icky way */ long fib ( int n ) { if ( n == 0 ) return 0; else if ( n == 1 ) return 1; else return fib ( n - 1 ) + fib ( n - 2 ); }
-Prelude
>The first two terms in the fibonacci sequence are 1, 1 right ?
The correct sequence should be:
0 1 1 2 3 5 8 13 21...
Without zero we wouldn't be able to do most of the things we can mathematically, so we can't forget it.
-Prelude
My best code is written with the delete key.
Prelude is correct -mathematically it starts at 0. However, most CS books start the sequence with 1 and 1 not 0 and 1. I prefer the math way starting at 0.
Mr. C