-
Notifications
You must be signed in to change notification settings - Fork 0
/
fizz.cob
35 lines (32 loc) · 937 Bytes
/
fizz.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
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-CNT PIC 9(3) VALUE 0.
01 FIZZ PIC 9(1).
01 BUZZ PIC 9(1).
01 FIZZBUZZ PIC 9(2).
01 DIV PIC 9(2).
01 DIV2 PIC 9(2).
01 DIV3 PIC 9(1).
PROCEDURE DIVISION.
A-PARA.
PERFORM B-PARA WITH TEST AFTER UNTIL WS-CNT>100.
STOP RUN.
B-PARA.
DIVIDE WS-CNT BY 3 GIVING DIV REMAINDER FIZZ.
DIVIDE WS-CNT BY 5 GIVING DIV2 REMAINDER BUZZ.
DIVIDE WS-CNT BY 15 GIVING DIV3 REMAINDER FIZZBUZZ.
IF FIZZBUZZ = 0 THEN
DISPLAY 'FIZZBUZZ'
ELSE
EVALUATE TRUE
WHEN FIZZ = 0
DISPLAY 'FIZZ'
WHEN BUZZ = 0
DISPLAY 'BUZZ'
WHEN OTHER
DISPLAY WS-CNT
END-EVALUATE
END-IF.
ADD 1 TO WS-CNT.