IDENTIFICATION DIVISION.
PROGRAM-ID. SUM-TO-N.
*> print the sum from 1 to N
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-SUM PIC 9(18) VALUE 0.
01 WS-N PIC 9(18) VALUE 0.
PROCEDURE DIVISION.
0000-main-logic.
DISPLAY 'N?'.
ACCEPT WS-N FROM CONSOLE.
PERFORM 1000-sum-n UNTIL WS-N=0.
DISPLAY WS-SUM.
STOP RUN.

1000-sum-n.

ADD WS-N TO WS-SUM.
SUBTRACT 1 FROM WS-N.
