COBOL
GnuCOBOL
Installation
Ubuntu
apt install gnucobol
Alma Linux
dnf install gnucobol
Arch Linux
pacman -S gnucobol
Examples
Fibonacci Numbers
* Fibonacci Numbers
IDENTIFICATION DIVISION.
FUNCTION-ID. FIBONACCI.
DATA DIVISION.
LOCAL-STORAGE SECTION.
01 t1 PIC 99.
01 t2 PIC 99.
LINKAGE SECTION.
01 n PIC 99.
01 r PIC 9(8).
PROCEDURE DIVISION USING n RETURNING r.
IF n = 0 THEN
COMPUTE r = 0
ELSE IF n = 1 THEN
COMPUTE r = 1
ELSE
COMPUTE t1 = n - 2
COMPUTE t2 = n - 1
COMPUTE r =
FUNCTION FIBONACCI (t1) +
FUNCTION FIBONACCI (t2)
END-IF.
EXIT FUNCTION.
END FUNCTION FIBONACCI.
IDENTIFICATION DIVISION.
PROGRAM-ID. FIB.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION FIBONACCI.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 99.
PROCEDURE DIVISION.
ACCEPT A FROM COMMAND-LINE
DISPLAY FUNCTION FIBONACCI (A).
STOP RUN.
*> Example
*> compile:
*> cobc -x fib.cob
*> run:
*> ./fib 30