Skip to content

Instantly share code, notes, and snippets.

@humbhenri
Created February 18, 2014 00:30
Show Gist options
  • Save humbhenri/9062158 to your computer and use it in GitHub Desktop.
Save humbhenri/9062158 to your computer and use it in GitHub Desktop.
IDENTIFICATION DIVISION.
PROGRAM-ID. EULERPROB1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 COUNTER PIC 9999 VALUE 1.
01 TOTAL PIC 9(6) VALUE 0.
01 REST PIC 999.
88 DIVISIBLE VALUE ZERO.
PROCEDURE DIVISION.
PERFORM SUM-IF-DIVISIBLE-BY-3-OR-5
VARYING COUNTER
FROM 1 BY 1
UNTIL COUNTER > 1000.
DISPLAY TOTAL.
STOP RUN.
SUM-IF-DIVISIBLE-BY-3-OR-5.
COMPUTE REST = FUNCTION MOD(COUNTER, 3).
IF DIVISIBLE
PERFORM ADD-TO-TOTAL
ELSE
PERFORM TEST-DIVISIBLE-5.
TEST-DIVISIBLE-5.
COMPUTE REST = FUNCTION MOD(COUNTER, 5).
IF DIVISIBLE
PERFORM ADD-TO-TOTAL.
ADD-TO-TOTAL.
ADD COUNTER TO TOTAL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment