-
Notifications
You must be signed in to change notification settings - Fork 0
/
021.cbl
54 lines (43 loc) · 1.42 KB
/
021.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
IDENTIFICATION DIVISION.
PROGRAM-ID. Euler021.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 n PIC 9(6) COMP.
01 ds1 PIC 9(6) COMP.
01 ds2 PIC 9(6) COMP.
01 res PIC 9(10) COMP VALUE 0.
01 out PIC Z(10).
PROCEDURE DIVISION.
PERFORM VARYING n FROM 1 BY 1 UNTIL n > 10000
CALL "Divsum" USING n, ds1
CALL "Divsum" Using ds1, ds2
IF n = ds2 AND n <> ds1 ADD n TO res
END-PERFORM
MOVE res TO out
DISPLAY FUNCTION TRIM (out)
STOP RUN.
END PROGRAM Euler021.
IDENTIFICATION DIVISION.
PROGRAM-ID. Divsum.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 d PIC 9(3) COMP.
01 q PIC 9(6) COMP.
01 rem PIC 9(6) COMP.
LINKAGE SECTION.
01 n PIC 9(6) COMP.
01 ds PIC 9(6) COMP.
PROCEDURE DIVISION USING n, ds.
MOVE 1 to ds.
PERFORM VARYING d FROM 2 BY 1 UNTIL d * d > n
DIVIDE n BY d GIVING q REMAINDER rem
IF rem = 0
IF q = d
ADD d to ds
ELSE
ADD d to ds
ADD q to ds
END-IF
END-IF
END-PERFORM.
END PROGRAM Divsum.