-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizzbuzz.cob
executable file
·40 lines (40 loc) · 1.49 KB
/
fizzbuzz.cob
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
IDENTIFICATION DIVISION.
PROGRAM-ID. FIZZBUZZ.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
CONSOLE IS TERM.
REPOSITORY.
FUNCTION ALL INTRINSIC.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 COUNTER PIC 9(04).
77 QUOTIENT PIC 9(03).
77 REST3 PIC 9(03).
77 REST5 PIC 9(03).
01 FIZZBUZZ-OUT PIC X(08).
01 COUNTER-OUT REDEFINES FIZZBUZZ-OUT PIC Z(08).
PROCEDURE DIVISION.
0000-MAIN.
PERFORM FIZZBUZZ VARYING COUNTER FROM 1 BY 1
UNTIL COUNTER > 1000.
9999-EXIT.
STOP RUN.
FIZZBUZZ SECTION.
DIVIDE COUNTER BY 3 GIVING QUOTIENT REMAINDER REST3.
DIVIDE COUNTER BY 5 GIVING QUOTIENT REMAINDER REST5.
MOVE COUNTER TO COUNTER-OUT.
EVALUATE REST3 ALSO REST5
WHEN 0 ALSO 0
MOVE "FIZZBUZZ" TO FIZZBUZZ-OUT
WHEN 0 ALSO NOT 0
MOVE "FIZZ" TO FIZZBUZZ-OUT
WHEN NOT 0 ALSO 0
MOVE "BUZZ" TO FIZZBUZZ-OUT
END-EVALUATE.
IF COUNTER < 1000
DISPLAY TRIM(FIZZBUZZ-OUT) " " WITH NO ADVANCING
UPON TERM
ELSE
DISPLAY TRIM(FIZZBUZZ-OUT) UPON TERM.
EXIT.