1. COBOL program on Arithmetic Operation
8. COBOL Program to REVERSE the entered Number.
9. COBOL Program to display Multiplication Table of Entered Number.
10. COBOL Program to SWAP Two Numbers.
11. COBOL Program to find SUM of N Numbers.
12. COBOL program to find Factorial of Given Number.
2. COBOL Program to display SUM and Average values*PROGRAM TO PERFRM ARITHMATIC OPERATIONS USING COMPUTE VERB.IDENTIFICATION DIVISION.PROGRAM-ID. AOP.ENVIRONMENT DIVISION.DATA DIVISION.WORKING-STORAGE SECTION.01 A PIC 9(4).01 B PIC 9(4).01 SUM PIC 9(4).01 SUB PIC 9(4).01 MUL PIC 9(4).01 DIV PIC 9(4).99.PROCEDURE DIVISION.START-PARA.DISPLAY "ENTER THE VALUES OF A AND B".ACCEPT A.ACCEPT B.COMPUTE SUM = A + B.COMPUTE SUB = A - B.COMPUTE MUL = A * B.COMPUTE DIV = A / B.DISPLAY "SUM = ", SUM.DISPLAY "SUB = ", SUB.DISPLAY "MUL = ", MUL.DISPLAY "DIV = ", DIV.STOP RUN.
*PROGRAM TO FIND SUM AND AVERAGE OF 6 NUMBERS.
IDENTIFICATION DIVISION.
PROGRAM-ID. SUM-AVG.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N1 PIC 9(4).
01 N2 PIC 9(4).
01 N3 PIC 9(4).
01 N4 PIC 9(4).
01 N5 PIC 9(4).
01 N6 PIC 9(4).
01 SUM PIC 9(6).
01 AVG PIC 9(4).99
PROCEDURE DIVISION.
START-PARA.
DISPLAY "ENTER VALUES FOR 6 NUMBERS".
ACCEPT N1.
ACCEPT N2.
ACCEPT N3.
ACCEPT N4.
ACCEPT N5.
ACCEPT N6.
COMPUTE SUM = N1 + N2 + N3 + N4 + N5 + N6.
COMPUTE AVG = SUM / 6.
DISPLAY "SUM = ", SUM.
DISPLAY "AVERAGE = ", AVG.
STOP RUN.3. COBOL Program to find Largest of Two Numbers
*PROGRAM TO FIND LARGEST OF 2 NUMBERS.
IDENTIFICATION DIVISION.
PROGRAM-ID. LARGEST2.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 9(4).
01 B PIC 9(4).
PROCEDURE DIVISION.
START-PARA.
DISPLAY "ENTER THE VALUE OF A AND B".
ACCEPT A.
ACCEPT B.
IF A > B
DISPLAY "A IS LARGEST",
ELSE
DISPLAY "B IS LARGEST.
STOP RUN.4. COBOL Program to display Largest of 3 Numbers
*PROGRAM TO LARGEST OF 3 NUMBERS.
IDENTIFICATION DIVISION.
PROGRAM-ID. LARGE3.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 9(4).
01 B PIC 9(4).
01 C PIC 9(4).
PROCEDURE DIVISION.
START-PARA.
DISPLAY " ENTER A ".
ACCEPT A.
DISPLAY " ENTER B ".
ACCEPT B.
DISPLAY " ENTER C ".
ACCEPT C.
IF ( A > B )
DISPLAY " A IS LARGEST ",
ELSE IF ( B > C )
DISPLAY " B IS LARGEST ",
ELSE
DISPLAY " C IS LARGEST ".
STOP RUN.5. COBOL Program to calculate Simple Interest
*PROGRAM TO FIND SIMPLE INTEREST.
IDENTIFICATION DIVISION.
PROGRAM-ID. SI.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 P PIC 9(4).
01 T PIC 9(4).
01 R PIC 9(4).
01 SI PIC 9(4).99.
PROCEDURE DIVISION.
START-PARA.
DISPLAY "ENTER PRINCIPLE AMOUNT : P".
ACCEPT P.
DISPLAY "ENTER TIME PERIOD : T".
ACCEPT T.
DISPLAY "ENTER RATE OF INTEREST : R".
ACCEPT R.
COMPUTE SI = P * T * R / 100.
DISPLAY "SIMPLE INTEREST = ", SI.
STOP RUN.6. COBOL program to calculate Compound Interest
*PROGRAM TO CALCUTE COMPOUND INTEREST.
IDENTIFICATION DIVISION.
PROGRAM-ID. CI.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 P PIC 9(4).
01 R PIC 9(4).
01 N PIC 9(4).
01 CI PIC 9(5).99.
PROCEDURE DIVISION.
START-PARA.
DISPLAY "ENTER PRINCIPLE AMOUNT : P".
ACCEPT P.
DISPLAY "ENTER RATE OF INTEREST : R".
ACCEPT R.
DISPLAY "ENTER PERIOD OF LOAN : N ".
ACCEPT N.
COMPUTE CI = P * ( 1 + R / 100 ) ** N - P.
DISPLAY "COMPOUND INTEREST = ", CI.
STOP RUN.7. COBOL Program to find the entered number is EVEN or ODD.
*PROGRAM TO FIND NUMBER IS EVEN 0R ODD.
IDENTIFICATION DIVISION.
PROGRAM-ID. EVEN-ODD.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N PIC 9(4).
01 REM PIC 9(4).
PROCEDURE DIVISION.
START-PARA.
DISPLAY "ENTER NUMBER".
ACCEPT N.
DIVIDE N BY 2 GIVING N REMAINDER REM.
IF REM = 0
DISPLAY " NUMBER IS EVEN ",
ELSE
DISPLAY " NUMBER IS ODD".
STOP RUN.
8. COBOL Program to REVERSE the entered Number.
IDENTIFICATION DIVISION.PROGRAM-ID. REV.ENVIRONMENT DIVISION.DATA DIVISION.WORKING-STORAGE SECTION.01 N PIC 9(6).01 REM PIC 9(4).01 REV PIC 9(6) value 0.PROCEDURE DIVISION.START-PARA.DISPLAY " ENTER THE NUMBER TO BE REVERSED ".ACCEPT N.PERFORM REV-PARA UNTIL N = 0.DISPLAY " REVERSED NUMBER = ", REV.STOP RUN.REV-PARA.DIVIDE N BY 10 GIVING N REMAINDER REM.COMPUTE REV = REV * 10 + REM.
9. COBOL Program to display Multiplication Table of Entered Number.
IDENTIFICATION DIVISION.
PROGRAM-ID. MTAB.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N PIC 9(2).
01 I PIC 9(2) VALUE 0.
01 P PIC 9(4).
PROCEDURE DIVISION.
START-PARA.
DISPLAY " ENTER THE NUMBER ".
ACCEPT N.
PERFORM MUL-PARA 10 TIMES.
STOP RUN.
MUL-PARA.
ADD 1 TO I.
COMPUTE P = N * I.
DISPLAY N " * " I " = " P.
10. COBOL Program to SWAP Two Numbers.
*PROGRAM TO SWAP TWO NUMBERS.
IDENTIFICATION DIVISION.
PROGRAM-ID. SWAP.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 9(2).
01 B PIC 9(2).
PROCEDURE DIVISION.
START-PARA.
DISPLAY " ENTER THE VALUE OF A & B ".
ACCEPT A.
ACCEPT B.
DISPLAY " THE VALUE OF A BEFORE SWAPPING ", A.
DISPLAY " THE VALUE OF B BEFORE SWAPPING ", B.
COMPUTE A = A + B.
COMPUTE B = A - B.
COMPUTE A = A - B.
DISPLAY "-------------------------------".
DISPLAY " THE VALUE OF A AFTER SWAPPING ", A.
DISPLAY " THE VALUE OF B AFTER SWAPPING ", B.
STOP RUN.
11. COBOL Program to find SUM of N Numbers.
*PROGRAM TO FIND SUM OF N NUMBER.
IDENTIFICATION DIVISION.
PROGRAM-ID. SUM-OF-N.
AUTHOR. MIT.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N PIC 9(3).
01 SUM PIC 9(6) VALUE IS 0.
PROCEDURE DIVISION.
START-PARA.
DISPLAY "PROGRAM TO FIND SUM OF N NUMBERS".
DISPLAY "ENTER THE RANGE".
ACCEPT N.
PERFORM SUM-PARA N TIMES.
DISPLAY " SUM = ", SUM.
STOP RUN.
SUM-PARA.
COMPUTE SUM = SUM + N.
COMPUTE N = N - 1.
12. COBOL program to find Factorial of Given Number.
Identification division.
Program-id. Fact.
Author. MIT.
Environment division.
Data division.
Working-storage section.
01 n pic 9(3).
01 x pic 9(8) value 1.
01 i pic 99.
procedure division.
Start-para.
display "Enter the no whose factorial is to calculated :".
accept n.
perform para-1 varying i from 1 by 1 until i > n.
display "The factorial of " n " is " x.
stop run.
para-1.
compute x = x * i.
No comments:
Post a Comment