Saturday, 1 March 2014

COBOL Program to implement IF Condition.



COBOL Program to implement IF Condition.


PROGRAM:

IDENTIFICATION DIVISION.
       PROGRAM-ID ARTH.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
           77 A PIC 9(3).
           77 B PIC 9(3).
           77 C PIC 9(3).
           77 D PIC 9(3).
       PROCEDURE DIVISION.
       PARA.
           DISPLAY "ENTER A,B VALUES".
           ACCEPT A.
           ACCEPT B.
       PARA1.
           DISPLAY "ENTER YOUR CHOICE 1.ADD, 2.SUB, 3.MUL, 4.DIV, 5.EXIT.
           ACCEPT D.
           IF (D = 1)
           GO TO ADD-PARA
           ELSE
           IF (D = 2)
           GO TO SUB-PARA
           ELSE
           IF (D = 3)
           GO TO MUL-PARA
           ELSE
           IF (D = 4)
           GO TO DIV-PARA
           ELSE
           GO TO END-PARA.
       ADD-PARA.
           ADD A B GIVING C.
           DISPLAY "ADDITION IS:", C.
           GO TO PARA1.
       SUB-PARA.
           SUBTRACT A FROM B GIVING C.
           DISPLAY "SUBTRACTION IS:", C.
           GO TO PARA1.
       MUL-PARA.
           MULTIPLY A BY B GIVING C.
           DISPLAY "MULTIPLICATION IS:", C.
           GO TO PARA1.
       DIV-PARA.
           DIVIDE A BY B GIVING C.
           DISPLAY "DIVISION IS:", C.
           GO TO PARA1.
       END-PARA.
           STOP RUN.

No comments: