How would a I make the loop so that it would keep generating it over nad over

Thanx in advance

Printable View

- 10-04-2002cprogFibonacci How should I make a generator
How would a I make the loop so that it would keep generating it over nad over

Thanx in advance - 10-04-2002Shadow
- 10-05-2002PCVsigh
Hey Cprog! Stop asking people here to do your homework for you.. hehe

the binary conversion was a bonus.. :cool: - 10-05-2002Shadow
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. - 10-05-2002MrWizardRe: Fibonacci How should I make a generatorQuote:

*Originally posted by cprog*

**How would a I make the loop so that it would keep generating it over nad over**

Thanx in advance

- 10-05-2002moiRe: Re: Fibonacci How should I make a generatorQuote:

*Originally posted by MrWizard*

**Look up the formula for calculating the nth term of the Fabonacci sequence and then use recursion.**

- 10-05-2002Cshot
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...

- 10-06-2002Prelude
>in the case of the fibonacci series, this is a horribly inefficient method

Only if you do it the icky way:

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 - 10-06-2002Max
An endless loop is

Code:

for (; ;)

- 10-06-2002Prelude
Or for the smiley challenged ;):

Code:`for ( ; ; )`

or

while ( 1 )

- 10-06-2002MrWizardQuote:

*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:

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

- 10-06-2002Prelude
>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 - 10-06-2002Mister C
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