-
Notifications
You must be signed in to change notification settings - Fork 0
/
016.cbl
30 lines (25 loc) · 941 Bytes
/
016.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
IDENTIFICATION DIVISION.
PROGRAM-ID. Euler016.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 carry PIC 9 COMP VALUE 0.
01 tmp PIC 9(2) COMP.
01 res PIC 9(4) COMP VALUE 0.
01 2p1000.
05 digs PIC 9 COMP VALUE 0 OCCURS 302 TIMES
INDEXED BY i.
01 out PIC Z(10).
PROCEDURE DIVISION.
MOVE 1 to digs(1)
PERFORM 1000 TIMES
PERFORM VARYING i FROM 1 BY 1 UNTIL i > 302
COMPUTE tmp = 2 * 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 > 302
ADD digs(i) TO res
END-PERFORM
MOVE res to out
DISPLAY FUNCTION TRIM (out)
STOP RUN.