COBOL program to print Even and
Odd Numbers between range using IF Condition.
PROGRAM:
IDENTIFICATION DIVISION.
PROGRAM-ID P2A.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NUM1 PIC 9(3).
01 NUM2 PIC 9(3).
01 R PIC 9(2).
01 N PIC 9(2).
01 I PIC 9(2).
01 J PIC 9(2).
01 M PIC Z(3).
PROCEDURE DIVISION.
DISPLAY-PARA.
DISPLAY 'ENTER THE LOWER LIMIT'.
DISPLAY '-----------------'.
ACCEPT NUM1.
DISPLAY 'ENTER THE UPPER LIMIT'.
DISPLAY '------------------------'.
ACCEPT NUM2.
IF NUM1 > NUM2
DISPLAY 'INVALID INPUT'
STOP RUN.
DISPLAY '-----------------------'.
DISPLAY 'LIST OF EVEN NUMBERS'.
DISPLAY '-------------------'.
PERFORM CAL-PARA VARYING I FROM NUM1
BY 1 UNTIL I>NUM2.
DISPLAY '----------------'.
DISPLAY 'LIST OF ODD NUMBERS'.
DISPLAY '---------------'.
PERFORM CAL1-PARA VARYING I FROM
NUM1 BY 1 UNTIL I>NUM2.
STOP RUN.
CAL-PARA.
DIVIDE I BY 2 GIVING N REMAINDER R.
IF R = 0
MOVE I TO J
DISPLAY SPACES " | " J
" | ".
CAL1-PARA.
DIVIDE I BY 2 GIVING N REMAINDER R.
IF R NOT = 0
MOVE I TO M
DISPLAY SPACES " | " M
" | ".
No comments:
Post a Comment