-
Notifications
You must be signed in to change notification settings - Fork 0
/
020.cbl
31 lines (26 loc) · 1003 Bytes
/
020.cbl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
IDENTIFICATION DIVISION.
PROGRAM-ID. Euler016.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 carry PIC 9(3) COMP VALUE 0.
01 tmp PIC 9(3) COMP.
01 res PIC 9(4) COMP VALUE 0.
01 n PIC 9(3) COMP.
01 fac100.
05 digs PIC 9 COMP VALUE 0 OCCURS 158 TIMES
INDEXED BY i.
01 out PIC Z(10).
PROCEDURE DIVISION.
MOVE 1 to digs(1)
PERFORM VARYING n FROM 1 BY 1 UNTIL n > 100
PERFORM VARYING i FROM 1 BY 1 UNTIL i > 158
COMPUTE tmp = n * digs(i) + carry
DIVIDE tmp BY 10 GIVING carry REMAINDER digs(i)
END-PERFORM
END-PERFORM
PERFORM VARYING i FROM 1 BY 1 UNTIL i > 158
ADD digs(i) TO res
END-PERFORM
MOVE res to out
DISPLAY FUNCTION TRIM (out)
STOP RUN.