Home   Easy-Code    Forum  Updater 
Twitter Facebook



Program to create two files ,one to store odd numbers and another to store even numbers in the given rang using cobol

Critics Rating:

Users Rating:

* PROGRAM TO CREATE TWO FILES ,ONE TO STORE ODD NUMBERS AND ANOTHER TO

*   STORE EVEN NUMBERS IN THE GIVEN RANGE.

**********************************************************************

   IDENTIFICATION DIVISION.

   PROGRAM-ID.

   ENVIRONMENT DIVISION.

   INPUT-OUTPUT SECTION.

   FILE-CONTROL.

      SELECT EVENFILE ASSIGN TO DISK

      ORGANIZATION IS LINE SEQUENTIAL.



      SELECT ODDFILE ASSIGN TO DISK

      ORGANIZATION IS LINE SEQUENTIAL.

   DATA DIVISION.

   FILE SECTION.

   FD EVENFILE

      LABEL RECORDS ARE STANDARD

      VALUE OF FILE-ID IS "EVEN.DAT".

   01 EVEN.

    02 E PIC Z(4).

   FD ODDFILE

      LABEL RECORDS ARE STANDARD

      VALUE OF FILE-ID IS "ODD.DAT".

   01 ODD.

    02 O PIC Z(4).

   WORKING-STORAGE SECTION.

   77 MIN PIC 9(4).

   77 MAX PIC 9(4).

   77 I PIC 9(4).

   77 Q PIC 9(4).

   77 R PIC 9(4).

   PROCEDURE DIVISION.

   MAIN-PARA.

      DISPLAY "ENTER THE RANGE OF THE NUMBERS".

      ACCEPT MIN.

      ACCEPT MAX.

      IF (MIN > MAX)

       DISPLAY "THE MINIMUM VALUE SHOULD BE ENTERED FIRST"

       STOP RUN.

      OPEN OUTPUT EVENFILE ODDFILE.

      PERFORM X-PARA VARYING I FROM MIN BY 1 UNTIL I > MAX.

      DISPLAY "SEE EVEN.DAT FOR EVEN NUMBERS AND ODD.DAT FOR"

                  " ODD NUMBERS".

      CLOSE EVENFILE ODDFILE.

      STOP RUN.

   X-PARA.

      DIVIDE I BY 2 GIVING Q REMAINDER R.

      IF (R = 0)

       MOVE I TO E

       WRITE EVEN

      ELSE

       MOVE I TO O

       WRITE ODD.

Courtesy, Source, References & Regards: Kishore AVGK

While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright@2009-2011 by KuGuNi.com. All Rights Reserved.