Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Fibonacci numbers

by claree0 (Hermit)
on Oct 02, 2001 at 14:40 UTC ( [id://116097]=note: print w/replies, xml ) Need Help??


in reply to Re: Fibonacci numbers
in thread Fibonacci numbers

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://116097]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-18 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found