in reply to Fibonacci numbers

Well i've tried this but is not giving the desired result...
$a=1; $b=1; $c=$a+$b; while($a <=100){ print("$a\n"); print("$b\n"); print("$c\n"); $a=$b+$c; $b=$a+$c; }

Replies are listed 'Best First'.
Re: Re: Fibonacci numbers
by claree0 (Hermit) on Oct 02, 2001 at 14:40 UTC

    OK, if you're going to make an attempt at it, then we can help

    Lets see....at the start you set $a and $b to 1, and $c to $a+$b = 2

    Then, on each iteration round the loop, you print out all three variables, then add 2 ($c from your initialisation) to $a and $b, then repeat.

    The assignment of $c=$a+$b simply sets $c according to the values of $a and $b at the time of assignment, and does not 'recalculate' on each trip around the loop.

    You will also have to rethink the calculation, as it doesn't quite work.

    p.s. try using strict and warnings.