Just another Perl shrine | |
PerlMonks |
Re: Re: Fibonacci numbersby claree0 (Hermit) |
on Oct 02, 2001 at 14:40 UTC ( [id://116097]=note: print w/replies, xml ) | Need Help?? |
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.
In Section
Seekers of Perl Wisdom
|
|