- 1. Cobol program to generate fiboncc series upto Nth terms.
- 2. Arthmetic operation to calculate (A-B)*C
- 3. cobol program to check whether given number is prime number or not.
- 4. Cobol program to generate even and odd number between the range value.
- 5. cobol program to compute income tax.
- 6. Cobol program to Sort a numbers
- 7. Cobol program to compute sum of N natural numbers.
- 8. Cobol program to compute sum of individual digits in given N digit decimal numbers.
- 9. Cobol program to compute Matrix addition and subtraction.
- 10. Cobol program to compute Matrix Multiplication.
- 11. WRITE A PROGRAM TO SORT RECORDS IN THE FILE USING SORT VERB..
TO COMPUTE A ARITHEMATIC EXPRESSION (A - B)*C.
IDENTIFICATION DIVISION. PROGRAM-ID. LAB1. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 A PIC S9(5)V99. 77 B PIC S9(5)V99. 77 C PIC S9(5)V99. 77 T PIC -ZZZZZ.ZZ 77 P PIC S9(5)V99. PROCEDURE DIVISION. PARA-1. DISPLAY "ENTER A B AND C:". ACCEPT A. ACCEPT B. ACCEPT C. COMPUTE P = ( A - B ) * C. MOVE P TO T. DISPLAY "ANSWER=" T. STOP RUN.
TO GENERATE A FIBONACCI SERIES.
IDENTIFICATION DIVISION. PROGRAM-ID. FIBONACCI. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 F1 PIC 9 value 0. 77 F2 PIC 9 value 1. 77 F3 PIC 9(3). 77 N PIC 99. 77 I PIC 99. PROCEDURE DIVISION. PARA-1. DISPLAY ( 1 , 1 ) ERASE. DISPLAY ( 2 , 1 ) "ENTER A NUMBER OF TERMS :". ACCEPT N. COMPUTE COL = 20. DISPLAY (5, 1) F1 " " F2. PERFORM PARA2 VARYING I FROM 2 BY 1 UNTIL I > N. STOP RUN. PARA2. COMPUTE F3 = F1 + F2. DISPLAY (5 , COL) F3. MOVE F2 TO F1. MOVE F3 TO F2. COMPUTE COL = COL + 5.
TO CHECK WHETHER GIVEN NUMBER IS PRIME OR NOT.
IDENTIFICATION DIVISION. PROGRAM-ID. PRIME. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 N PIC 9(3). 77 Q PIC 9(3). 77 R PIC 9(3). 77 I PIC 9(3). PROCEDURE DIVISION. PARA-A. DISPLAY ( 1 , 1 ) ERASE. DISPLAY ( 2 , 1 ) "ENTER AN INTEGER:". ACCEPT ( 2 , 20 ) N. PERFORM PARA2 VARYING I FROM 2 BY 1 UNTIL I > N. STOP RUN. PARA2. DIVIDE N BY I GIVING Q REMAINDER R. IF R==0 DISPLAY(5, 1) "NOT PRIME" ELSE DISPLAY(5, 1) "PRIME".
TO CALCUATE THE INCOME TAX
IDENTIFICATION DIVISION. PROGRAM-ID. Q9. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM PC. OBJECT-COMPUTER. IBM PC. INPUT-OUTPUT SECTION. SELECT IN-FILE ASSIGN TO "Q9IN.DAT" ORGANIZATION IS LINE SEQUENTIAL. SELECT OUT-FILE ASSIGN TO "Q9OUT.TXT". DATA DIVISION. FILE SECTION. FD IN-FILE. 01 IN-REC. 02 IN-NAME PIC A(20). 02 IN-INCOME PIC 9(6)V99. FD OUT-FILE. 01 OUT-REC PIC X(80). WORKING-STORAGE SECTION. 77 EOF PIC X value "N". 77 HEADING1 PIC X(80) VALUE ALL "-". 77 TAX PIC 9(5)V99. 01 OUT-FORMAT. 02 OUT-NAME PIC X(5). 02 F PIC X(15) VALUE SPACES. 02 OUT-INCOME PIC ***9(3).99. 02 F PIC X(10) VALUE SPACES. 02 OUT-TAX PIC ***9(2).99. PROCEDURE DIVISION. MAIN-PARA. OPEN INPUT IN-FILE OUTPUT OUT-FILE. READ IN-FILE AT END MOVE "Y" TO EOF. PERFORM CALC-PARA UNTIL EOF = "Y". DISPLAY "THE DETAILS HAVE BEEN WRITTEN TO FILE Q9OUT.DAT". CLOSE IN-FILE , OUT-FILE. STOP RUN. CALC-PARA. IF IN-INCOME IS NOT > 150000 SUBTRACT 50000 FROM IN-INCOME , MULTIPLY 0.30 BY IN-INCOME GIVING TAX , ADD 9000 TO TAX. IF IN-INCOME IS NOT > 70000 SUBTRACT 50000 FROM IN-INCOME , MULTIPLY 0.20 BY IN-INCOME GIVING TAX , ADD 5000 TO TAX. IF IN-INCOME IS NOT > 50000 SUBTRACT 20000 FROM IN-INCOME , MULTIPLY 0.10 BY IN-INCOME GIVING TAX. IF IN-INCOME IS NOT > 20000 MOVE ZERO TO TAX. MOVE " INCOME TAX SLIP " TO OUT-REC. WRITE OUT-REC. WRITE OUT-REC FROM HEADING1. MOVE " NAME | INCOME | INCOME-TAX " TO OUT-REC. WRITE OUT-REC. WRITE OUT-REC FROM HEADING1. MOVE IN-NAME TO OUT-NAME. MOVE IN-INCOME TO OUT-INCOME. MOVE TAX TO OUT-TAX. WRITE OUT-REC FROM OUT-FORMAT. READ IN-FILE AT END MOVE "Y" TO EOF.
COBOL PROGRAM TO SORT THE INTEGER NUMBERS USING ARRAY..
IDENTIFICATION DIVISION. PROGRAM-ID. SORT. ENVIRONEMNT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. O1 MYARRAY. 02 ARR PIC S999 OCCURS 20 TIMES. 77 N PIC 99. 77 I PIC 99. 77 J PIC 99. 77 M PIC -ZZZ. 77 T PIC S999. PROCEDURE DIVISION. PARA1. DISPLAY(1, 1) ERASE. DISPLAY (2, 1) "ENTER AN ARRAY LIMIT :". ACCEPT N. DISPLAY "ENTER ARRAY ELEMENTS :". PERFORM PARA2 VARYING I FROM 1 BY 1 UNTIL I > N. PERFORM SORTPARA VARYING I FROM 1 BY 1 UNTIL I >N AFTER J FROM 1 BY 1 UNTIL J >N. DISPLAY "AFTER SORTING". PERFORM PARA3 VARYING I FROM 1 BY 1 UNTIL I > N. STOP RUN. PARA2. ACCEPT ARR(I). SORTPARA. IF (ARR(I) > ARR(J)) COMPUTE T = ARR(I) COMPUTE ARR(I) = ARR(J) COMPUTE ARR(J) = T.
COBOL PROGRAM TO GENERATE A EVEN AND ODD NUMBER BETWEEN THE RANGE VALUE.
IDENTIFICATION DIVISION. PROGRAM-ID. SORT. ENVIRONEMNT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 UP1 PIC 99. 77 LOW1 PIC 99. 77 I PIC 99. 77 REM PIC 99. 77 Q PIC 999. PROCEDURE DIVISION. PARA1. DISPLAY (1, 1) ERASE. DISPLAY (2, 1) "ENTER THE LOWER LIMIT:". ACCEPT LOW. COMPUTE COL = 5. DISPLAY (4, 1) "ENTER THE UPPER LIMIT:". ACCEPT UP1. DISPLAY(1 ,1 ) ERASE. DISPLAY (9, COL) "EVEN". DISPLAY (14 , COL) "ODD". PERFORM LOOPPARA VARYING I FROM LOW1 BY 1 UNTIL I > UP1. STOP RUN. LOOPPARA. DIVIDE I BY 2 GIVING Q REMAINDER REM. IF REM == 0 DISPLAY (10 , COL ) I ELSE DISPLAY ( 15 , COL) I. COMPUTE COL = COL + 3.
program to calcutae sum of N natural numbers
IDENTIFICATION DIVISION. PROGRAM-ID. SORT. ENVIRONEMNT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 A PIC 99999 VALUE 1. 77 N PIC 99999. 77 T PIC 99999 ZZZZZ. 77 S PIC 99999 VALUE 1. PROCEDURE DIVISION. PARA1. DISPLAY"ENTER LIMIT:". ACCEPT N. PERFORM PARA2 UNTIL A > N. MOVE S TO T. DISPLAY "SUM OF N NATURAL NUMBER=" T. STOP RUN. PARA2. COMPUTE S = S + A. COMPUTE A = A + 1.
Cobol program to compute sum of individual digits in given N digit decimal numbers
IDENTIFICATION DIVISION. PROGRAM-ID. SUMOFDIGIT. ENVIRONEMNT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 N1 PIC ZZZZZ. 77 N PIC 99999. 77 S PIC 999 VALUE 0. 77 R PIC 99. PROCEDURE DIVISION. PARA1. DISPLAY "ENTER THE NUMBER:". ACCEPT N. PERFORM PARA2 UNTIL N = 0. MOVE S TO N1. DISPLAY "SUM OF DIGITS:". DISPLAY N1. STOP RUN. PARA2. DIVIDE N BY 10 GIVING N REMAINDER R. COMPUTE S = S + R.
Cobol program to compute Matrix addition and subtraction.
IDENTIFICATION DIVISION. PROGRAM-ID. MATADD. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 MAT-A. 02 A1 OCCURS 3 TIMES. 03 A2 OCCURS 3 TIMES. 04 A3 PIC 999. 01 MAT-B. 02 B1 OCCURS 3 TIMES. 03 B2 OCCURS 3 TIMES. 04 B3 PIC 999. 01 MAT-C. 02 C1 OCCURS 3 TIMES. 03 C2 OCCURS 3 TIMES. 04 C3 PIC 999. 01 MAT-D. 02 D1 OCCURS 3 TIMES. 03 D2 OCCURS 3 TIMES. 04 D3 PIC 999. 01 I PIC 99. 01 J PIC 99. PROCEDURE DIVISION. P1. DISPLAY "ENTER ELEMENTS OF 1ST MATRIX : ". PERFORM ACC1 VARYING I FROM 1 BY 1 UNTIL I > 3 AFTER J FROM 1 BY 1 UNTIL J > 3. DISPLAY "ENTER ELEMENTS OF 2ND MATRIX : ". PERFORM ACC2 VARYING I FROM 1 BY 1 UNTIL I > 3 AFTER J FROM 1 BY 1 UNTIL J > 3. MOVE 1 TO J. DISPLAY "ELEMENTS OF 1ST MATRIX :". PERFORM DIS1 VARYING I FROM 1 BY 1 UNTIL I > 3. DISPLAY " ". DISPLAY "ELEMENTS OF 2ND MATRIX :". PERFORM DIS2 VARYING I FROM 1 BY 1 UNTIL I > 3. DISPLAY " ". PERFORM CAL1 VARYING I FROM 1 BY 1 UNTIL I > 3 AFTER J FROM 1 BY 1 UNTIL J > 3. PERFORM CAL2 VARYING I FROM 1 BY 1 UNTIL I > 3 AFTER J FROM 1 BY 1 UNTIL J > 3. DISPLAY "MATRIX ADDITION : ". MOVE 1 TO J. PERFORM DIS3 VARYING I FROM 1 BY 1 UNTIL I > 3. DISPLAY " ". DISPLAY "MATRIX SUBTRACTION : ". MOVE 1 TO J. PERFORM DIS4 VARYING I FROM 1 BY 1 UNTIL I > 3. DISPLAY " ". DISPLAY " ". STOP RUN. ACC1. ACCEPT A3(I , J). DIS1. DISPLAY A3( I , J ) , " " , A3( I , J + 1 ) , " " , A3( I , J + 2 ). ACC2. ACCEPT B3(I , J). DIS2. DISPLAY B3( I , J ) , " " , B3( I , J + 1 ) , " " , B3( I , J + 2 ). CAL1. COMPUTE C3( I , J ) = A3( I , J ) + B3( I , J ). DIS3. DISPLAY C3( I , J ) , " " , C3( I , J + 1 ) , " " , C3( I , J + 2 ). CAL2. COMPUTE D3( I , J ) = A3( I , J ) - B3( I , J ). DIS4. DISPLAY D3( I , J ) , " " , D3( I , J + 1 ) , " " , D3( I , J + 2 ).
cobol program to compute matrix multiplication
IDENTIFICATION DIVISION. PROGRAM-ID. MATADD. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 MAT-A. 02 A1 OCCURS 3 TIMES. 03 A2 OCCURS 3 TIMES. 04 A3 PIC 999. 01 MAT-B. 02 B1 OCCURS 3 TIMES. 03 B2 OCCURS 3 TIMES. 04 B3 PIC 999. 01 MAT-C. 02 C1 OCCURS 3 TIMES. 03 C2 OCCURS 3 TIMES. 04 C3 PIC 999. 01 I PIC 99. 01 J PIC 99. 01 K PIC 99. PROCEDURE DIVISION. P1. DISPLAY "ENTER THE ELEMENTS OF 1ST MATRIX :". PERFORM ACC1 VARYING I FROM 1 BY 1 UNTIL I > 3 AFTER J FROM 1 BY 1 UNTIL J > 3. DISPLAY "ENTER THE ELEMENTS OF 2ND MATRIX :". PERFORM ACC2 VARYING I FROM 1 BY 1 UNTIL I > 3 AFTER J FROM 1 BY 1 UNTIL J > 3. MOVE 1 TO J. DISPLAY " 1ST MATRIX :". DISPLAY " ". PERFORM DIS1 VARYING I FROM 1 BY 1 UNTIL I > 3. DISPLAY " ". DISPLAY "2ND MATRIX :". DISPLAY " ". PERFORM DIS2 VARYING I FROM 1 BY 1 UNTIL I > 3. DISPLAY " ". PERFORM CAL1 VARYING I FROM 1 BY 1 UNTIL I > 3 AFTER J FROM 1 BY 1 UNTIL J > 3. DISPLAY "MUTIPLIED MATRIX : ". DISPLAY " ". MOVE 1 TO J. PERFORM DIS3 VARYING I FROM 1 BY 1 UNTIL I > 3. DISPLAY " ". DISPLAY " ". STOP RUN. ACC1. ACCEPT A3(I , J). DIS1. DISPLAY A3( I , J ) , " " , A3( I , J + 1 ) , " " , A3( I , J + 2 ). ACC2. ACCEPT B3(I , J). DIS2. DISPLAY B3( I , J ) , " " , B3( I , J + 1 ) , " " , B3( I , J + 2). CAL1. COMPUTE C3(I , J) = 0. PERFORM CAL2 VARYING K FROM 1 BY 1 UNTIL K > 3. CAL2. COMPUTE C3(I , J) = C3(I , J) + A3(I , K) * B3(K , J). DIS3. DISPLAY C3( I , J ) , " " , C3( I , J + 1 ) , " " , C3( I , J + 2)..
11. WRITE A PROGRAM TO SORT RECORDS IN THE FILE USING SORT VERB
IDENTIFICATION DIVISION. PROGRAM-ID. PRA. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMP-FILE ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. SELECT SORT-FILE ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. SELECT OUT-FILE ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD EMP-FILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "EMP1.DAT". 01 EMP-REC. 02 ID-NO PIC 9(3). 02 NAME PIC X(10). 02 DEPT PIC X(10). 02 SALARY PIC 9(7). SD SORT-FILE DATA RECORDS ARE SORTREC. 01 SORTREC. 02 ID-NO PIC 9(3). 02 NAME PIC X(10). 02 DEPT PIC X(10). 02 SALARY PIC 9(7). FD OUT-FILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "RESULT.DAT". 01 OUTREC PIC X(80). PROCEDURE DIVISION. P1. SORT SORT-FILE ON ASCENDING KEY NAME OF SORTREC USING EMP-FILE GIVING OUT-FILE. STOP RUN.
10:43 AM |
Category: |