HP Forums

Full Version: 48SX Fibonacci (with a few tricks)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So, I'm new on the forums and own an 11C, a 28S, and a 48SX. I was wondering how to make a program of the Fibonacci sequence that left the numbers on the stack. The code that I use normally is:
-start with 2 1s on the stack-
<<
DO
DUP ROT +
CLLCD DUP 5 DISP 1 WAIT
UNTIL KEY END
>>
This displays the numbers but doesn't leave them on the stack.
(04-25-2018 01:58 PM)SamE Wrote: [ -> ]This displays the numbers but doesn't leave them on the stack.

Welcome to the forum, SamE!

You've got a good start on this already. Using the same basic structure as what you already have above, here's one way to leave the numbers on the stack as they are being displayed:
Code:
«
  CLLCD
  1 DUP
  DO
    DUP2 +
    DUP 5 DISP
    1 WAIT
  UNTIL
    KEY
  END
  DROP
»

Notes:
- I moved the CLLCD outside of the loop, as it doesn't really need to be executed each time.
- Since you need to start with two 1s on the stack, I went ahead and included that as a convenience.
- "DO ... UNTIL KEY END" leaves the pressed key code on the stack. That isn't a part of the sequence, so I thought it might be good to DROP it at the end instead of leaving it in place.
That is exactly what I needed and works great! Thanks.
Reference URL's