-
Notifications
You must be signed in to change notification settings - Fork 11
/
fizzbuzz.cob
46 lines (42 loc) · 1.75 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
41
42
43
44
45
46
* LANGUAGE: COBOL
* Web site: https://sourceforge.net/projects/gnucobol/
* Last tested on: Ubuntu 22.04.5
* Requires: apt-get install gnucobol
IDENTIFICATION DIVISION.
PROGRAM-ID. FIZZBUZZ.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Variables.
05 I PIC 999 VALUE ZERO.
05 Counting PIC 99 VALUE ZERO.
05 Start-Position PIC 99 VALUE ZERO.
05 Positions PIC 99 VALUE ZERO.
05 ignored PIC S99 VALUE ZERO.
05 I-MOD-15 PIC S99 VALUE ZERO.
05 I-MOD-3 PIC S99 VALUE ZERO.
05 I-MOD-5 PIC S99 VALUE ZERO.
PROCEDURE DIVISION.
PERFORM VARYING I FROM 1 BY 1 UNTIL I IS GREATER THAN 100
DIVIDE I BY 15 GIVING ignored REMAINDER I-MOD-15
IF I-MOD-15 IS EQUAL TO ZERO
DISPLAY "FizzBuzz"
ELSE
DIVIDE I BY 3 GIVING ignored REMAINDER I-MOD-3
IF I-MOD-3 IS EQUAL TO ZERO
DISPLAY "Fizz"
ELSE
DIVIDE I BY 5 GIVING ignored REMAINDER I-MOD-5
IF I-MOD-5 IS EQUAL TO ZERO
DISPLAY "Buzz"
ELSE
MOVE ZEROES TO Counting
INSPECT I,
TALLYING Counting FOR LEADING ZEROES
ADD 1 TO Counting GIVING Start-Position
SUBTRACT Counting FROM 3 GIVING Positions
DISPLAY I(Start-Position:Positions)
END-IF
END-IF
END-IF
END-PERFORM
STOP RUN.