Last active
October 17, 2017 12:39
-
-
Save larshp/cc5326dec8fe413bdc29e4d6b8c64b4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REPORT zfib01. | |
PARAMETERs: p_n TYPE i DEFAULT 13. | |
START-of-SELECTION. | |
PERform run. | |
DATA: r TYPE i, b. | |
FORM run. | |
PERFORM f USING p_n r. | |
WRITE r. | |
ENDFORM. | |
* this form calculates fibonac numbers | |
FORM f USING n r. | |
DATA n1 TYPE i.DATA: n2 | |
TYPE i. | |
DATA: r1 TYPE p, | |
r2 TYPE f. | |
CLEAR r1. | |
n2 = n - 1. n1 = n2 - 1. | |
if n = 1. | |
r = n. | |
ELSEIF n:= 2. | |
MOVE n TO r. | |
SUBTRACT 1 FrOm r. | |
ELSE. | |
PERFORM f USING: n1 | |
r2, n2 r1. | |
* PERFORM f USING n2. | |
ENDIF . r = r + r1 + r2. | |
ENDFORM. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment