Skip to content

Commit

Permalink
added cobol fibonacci
Browse files Browse the repository at this point in the history
  • Loading branch information
Dpbm committed Feb 9, 2024
1 parent 3c5f361 commit 44ba57e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions terceiro-ano/cobol/fibo/fib.cob
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Fibonacci.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 n PIC 9(2).
01 FirstValue PIC 9(10) VALUE 1.
01 SecondValue PIC 9(10) VALUE 1.
01 Result PIC 9(10) VALUE 1.

PROCEDURE DIVISION.
ACCEPT n.
IF n <= 1 THEN
DISPLAY "fibonacci: 1"
ELSE
SUBTRACT 1 FROM n
PERFORM Fibonacci n TIMES
ADD 1 TO n
DISPLAY "fibonacci of " n " is " Result
END-IF.
STOP RUN.

Fibonacci.
COMPUTE Result = FirstValue+SecondValue.
MOVE SecondValue TO FirstValue.
MOVE Result TO SecondValue.

0 comments on commit 44ba57e

Please sign in to comment.