Skip to content

Modernising COBOL takes time and care

wethebuilders.org
4 pointsnonrandomstring2 comments
On HN

Comments

Hey Grok, Can you write the simplest recursive fibonacci-generator in COBOL?

       IDENTIFICATION DIVISION.
       PROGRAM-ID. FIBONACCI.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  NUM         PIC 9(10).
       01  RESULT      PIC 9(10).
       PROCEDURE DIVISION.
       MAIN-PARA.
           MOVE 10 TO NUM
           CALL 'FIB' USING NUM RESULT
           DISPLAY 'FIBONACCI OF ' NUM ' IS ' RESULT
           STOP RUN.
       IDENTIFICATION DIVISION.
       PROGRAM-ID. FIB.
       DATA DIVISION.
       LINKAGE SECTION.
       01  N           PIC 9(10).
       01  FIB-RESULT  PIC 9(10).
       PROCEDURE DIVISION USING N FIB-RESULT.
           IF N <= 1
               MOVE N TO FIB-RESULT
           ELSE
               COMPUTE FIB-RESULT = FUNCTION FIB(N - 1) + FUNCTION FIB(N - 2)
           END-IF
           GOBACK.
       END PROGRAM FIB.
       END PROGRAM FIBONACCI.

Has recursion. OK.

There was a time, when I learned Fortran does not allow recursion. "You stupid or what?" said the professor.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.