Created
February 18, 2014 00:30
-
-
Save humbhenri/9062158 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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