COBOL Program to implement Linear Search Concept
PROGRAM:
IDENTIFICATION DIVISION.
PROGRAM-ID LINEAR.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 ARRY.
02 A1 PIC 9(4)V99 OCCURS 8 TIMES.
77 I PIC 9(3).
77 N PIC 9(3).
77 ELE PIC 9(4)V99.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY "ENTER THE TOTAL NUMBER
OF ELEMENTS".
ACCEPT N.
DISPLAY " ".
DISPLAY "ENTER THE
ELEMENTS".
PERFORM ACC-PARA VARYING I FROM 1 BY
1 UNTIL I > N.
DISPLAY "-----------".
DISPLAY "ENTER THE KEY ELEMENT
TO BE SEARCHED".
ACCEPT ELE.
SEARCH-PARA.
PERFORM FIND-PARA VARYING I FROM 1
BY 1 UNTIL I > N.
DISPLAY "THE ELEMENT IS
NOT FOUND IN THE LIST !!!".
STOP RUN.
ACC-PARA.
ACCEPT A1 (I).
FIND-PARA.
IF A1 (I) IS EQUAL TO ELE
DISPLAY "THE ELEMENT IS FOUND
AT POSITION:", I
STOP RUN.
No comments:
Post a Comment