CoCalc Public Filescobol / factorial.cobOpen with one click!
Author: Harald Schilly
License: Apache License 2.0
Description: run cobol programs via OpenCOBOL
Compute Environment: Ubuntu 18.04 (Deprecated)
1
*> Open COBOL -- https://open-cobol.sourceforge.io/
2
*> This program computes the factorial of n
3
*> Run it in the terminal with these two commands:
4
*> 1. $ cobc -x factorial.cob
5
*> 2. $ ./factorial
6
7
IDENTIFICATION DIVISION.
8
PROGRAM-ID. Factorial.
9
10
DATA DIVISION.
11
WORKING-STORAGE SECTION.
12
01 n BINARY-LONG.
13
01 i BINARY-LONG.
14
01 prod BINARY-LONG VALUE 1.
15
16
PROCEDURE DIVISION.
17
DISPLAY "Enter a positive integer (e.g. 10)"
18
ACCEPT n
19
PERFORM VARYING i FROM 1 BY 1 UNTIL i > n
20
MULTIPLY prod BY i GIVING prod
21
END-PERFORM
22
DISPLAY "The factorial of " n " is " prod ".".
23