Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

Program of bubble sort

Posted By: Mia Brown     Category: Cobol     Views: 10449

Write a Program of bubble sort.

Code for Program of bubble sort in Cobol

       IDENTIFICATION DIVISION.
        PROGRAM-ID. PRG1.
       DATA DIVISION.
           77 ARR OCCURS 5 TIMES PIC S9(2).
           77 TEMP PIC 999 VALUE 000.
           77 I PIC 9 VALUE 0.
           77 J PIC 9 VALUE 1.
       PROCEDURE DIVISION.
       DISP.
           DISPLAY "ENTER ANY FIVE NUMBERS:"
           PERFORM UNTIL I = 5
           ADD 1 TO I  
           ACCEPT ARR(I)
           END-PERFORM.
           MOVE 1 TO I.
           PERFORM UNTIL I > 5
           MOVE I TO J
           PERFORM UNTIL J > 5 
             IF (ARR(I) > ARR(J))
               MOVE ARR(I) TO TEMP
               MOVE ARR(J) TO ARR(I)
               MOVE TEMP TO ARR(J)
             END-IF
           ADD 1 TO J GIVING J
           END-PERFORM
           ADD 1 TO I GIVING I
           END-PERFORM.
           MOVE 0 TO I.
           PERFORM UNTIL I = 5
           ADD 1 TO I  
           DISPLAY  I ":=" ARR(I)
           END-PERFORM.
        
        STOP RUN.
    
    ENTER ANY FIVE NUMBERS:
    78
    23
    45
    56
    21

    AFTER SORTING:
    21
    23
    45
    56
    78
    
  
Share: 


Didn't find what you were looking for? Find more on Program of bubble sort Or get search suggestion and latest updates.

Mia Brown
Mia Brown author of Program of bubble sort is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!