Tuesday, January 10, 2012

Program to check evenness & oddness and bubble sort


       IDENTIFICATION DIVISION.
       PROGRAM-ID "EVEN-ODD".
       AUTHOR "ABC".
       DATE-WRITTEN 04/01/2012.
       DATE-COMPILED 04/01/2012.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER P4.
       OBJECT-COMPUTER P4.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 N PIC 99.
       77 Q PIC 99.
       77 R PIC 99.

       01 AR-DATA.
       02 AR PIC 9 OCCURS 5 TIMES.
       77 I PIC 9 VALUE IS 0.
       77 J PIC 9 VALUE IS 0.
       77 K PIC 9 VALUE IS 0.
       77 TEMP PIC 9 VALUE 0.
       PROCEDURE DIVISION.
       START-PARA.
        DISPLAY "FOR EVEN ODD".
        DISPLAY "ENTER NUM".
        ACCEPT N.
DIVIDE N BY 2 GIVING Q REMAINDER R.
        IF R=0
DISPLAY N "IS AN EVEN NUMBER"
ELSE  
DISPLAY N "IS AN ODD NUMBER".
       END-PARA.
DISPLAY "FOR BUBBLE SORT".
DISPLAY "ENTER ELEMENTS".
        PERFORM PARA1 VARYING I FROM 0 BY 1 UNTIL I>4.
PERFORM PARA2 VARYING I FROM 0 BY 1 UNTIL I>4
AFTER J FROM 0 BY 1 UNTIL J>3.
DISPLAY "SORTED LIST:".
PERFORM PARA3 VARYING I FROM 0 BY 1 UNTIL I>4.
STOP RUN.

PARA1.
ACCEPT AR(I).
PARA2.
COMPUTE K = J + 1.
IF AR(J)>AR(K)
MOVE AR(J) TO TEMP
MOVE AR(K) TO AR(J)
MOVE TEMP TO AR(K).
PARA3.
DISPLAY AR(I).
       

No comments:

Post a Comment