Cobol
Cobol
Cobol
IDENTIFICATION DIVISION.
PROGRAM-ID. THREE.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 A PIC S99V99.
77 B PIC S99V99.
77 C PIC S99V99.
77 D PIC S999V99.
PROCEDURE DIVISION.
PARA.
DISPLAY "ENTER THREE NUMBERS".
ACCEPT A.
ACCEPT B.
ACCEPT C.
COMPUTE D = ( A - B ) * C.
DISPLAY "OUT PUT IS:", D.
STOP RUN.
OUT PUT
ENTER THREE NUMBERS
10
20
30
OUT PUT IS : 300
LAB 1B
IDENTIFICATION DIVISION.
PROGRAM-ID. SUM.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 N PIC 9(5).
77 S PIC 9(3) VALUE 0.
77 N1 PIC Z(5).
77 R PIC 99.
PROCEDURE DIVISION.
PARA-1.
DISPLAY "ENTER THE VALUE:".
ACCEPT N.
PERFORM PARA-2 UNTIL N=0.
MOVE S TO N1.
DISPLAY "SUM OF THE DIGITS:", N1.
STOP RUN.
PARA-2.
DIVIDE N BY 10 GIVING N REMAINDER R.
COMPUTE S = S + R.
OUT PUT
ENTER THE VALUE
123
SUM OF THE DIGITS : 6.
LAB-2A
IDENTIFICATION DIVISION.
PROGRAM-ID. EVEN.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 L1 PIC 9(2).
77 L2 PIC 9(2).
77 I PIC 99 VALUE 0.
77 Q PIC 99.
77 R PIC 99.
PROCEDURE DIVISION.
PARA-1.
DISPLAY "ENTER THE LIMIT IN ASCENDING ORDER".
ACCEPT L1.
ACCEPT L2.
IF L1 > L2
COMPUTE Q = L1
COMPUTE L1 = L2
COMPUTE L2 = Q
COMPUTE COL = 1.
DISPLAY (5, 2) ERASE.
DISPLAY (5, 10) "EVEN NO".
DISPLAY (7, 10) "ODD NO".
PERFORM PARA-2 VARYING I FROM L1 BY 1 UNTIL I > L2.
STOP RUN.
PARA-2.
DIVIDE I BY 2 GIVING Q REMAINDER R.
IF R = 0
DISPLAY (4, COL) I
ELSE
DISPLAY (6, COL) I.
COMPUTE COL = COL + 2.
OUTPUT
ENTER LIMITS IN ASCENDING ORDER
10 20
EVEN NUMBERS
12 14 16 18 20
ODD NUMBERS
11 13 15 17 19
LAB 2B
IDENTIFICATION DIVISION.
PROGRAM-ID. LENGTH.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 LIST.
02 A PIC S9(3)V9(2) OCCURS 10 TIMES.
77 I PIC 9(3).
77 J PIC 9(3).
77 N PIC 9(3).
77 TEMP PIC S9(3).
77 C PIC -9(3).9(2).
PROCEDURE DIVISION.
PARA.
DISPLAY " ENTER THE LENGTH OF ARRAY ".
ACCEPT N.
DISPLAY " ENTER THE ARRAY ELEMENTS ".
PERFORM GETDATA VARYING I FROM 1 BY 1 UNTIL I>N.
DISPLAY " ARRAY STATEMENTS BEFORE SORT ".
PERFORM DIS-PARA VARYING I FROM 1 BY 1 UNTIL I>N.
PERFORM SORT-PARA VARYING I FROM 1 BY 1 UNTIL I>N
AFTER J FROM 1 BY 1 UNTIL J>N.
DISPLAY "ARRAY ELEMENTS AFTER SORTING".
PERFORM DIS-PARA VARYING I FROM 1 BY 1 UNTIL I>N.
STOP RUN.
GETDATA.
ACCEPT A(I).
DIS-PARA.
MOVE A(I) TO C.
DISPLAY C.
SORT-PARA.
IF A(I) < A(J)
MOVE A(I) TO TEMP
MOVE A(J) TO A(I)
MOVE TEMP TO A(J).
OUTPUT
ENTER THE LENGTH OF ARRAY
5
ENTER THE ARRAY ELEMENTS
2
5
4
9
8
ARRAY STATEMENTS BEFORE SORT
002.00
005.00
004.00
009.00
008.00
ARRAY ELEMENTS AFTER SORTING
002.00
004.00
005.00
008.00
009.00
LAB 3
IDENTIFICATION DIVISION.
PROGRAM-ID. SEARCH.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMP-FILE ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD EMP-FILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS "EMP.DAT".
01 EMP-REC.
02 ENO PIC X(5).
02 ENAME PIC X(20).
02 BASIC PIC 9(5).
WORKING-STORAGE SECTION.
77 F PIC 9 VALUE 0.
77 SNO PIC X(5).
77 SNAME PIC X(20).
77 BP PIC 9(5).
PROCEDURE DIVISION.
PARA-1.
OPEN INPUT EMP-FILE.
DISPLAY "ENTER SEARCHING EMP NO".
ACCEPT SNO.
DISPLAY (1, 1) ERASE.
PERFORM EMP-READ.
EMP-READ.
READ EMP-FILE AT END GO TO END-PARA.
DISPLAY EMP-REC.
IF ENO=SNO
COMPUTE F=1
MOVE ENAME TO SNAME
MOVE BASIC TO BP.
GO TO EMP-READ.
END-PARA.
CLOSE EMP-FILE.
IF F=0
DISPLAY (20, 10) SNO "NOT FOUND"
ELSE
DISPLAY (20, 10) "SEARCHING EMPNO" SNO
DISPLAY (21, 10) "EMPNAME" SNAME
DISPLAY (22, 10) "BASIC(RS)" BP.
STOP RUN.
OUTPUT
111 VEERESH 10000
222 SUMAN 20000
SEARCHING EMPNO111
EMPNAMEVEERESH
BASIC(RS)10000
LAB 4A
IDENTIFICATION DIVISION.
PROGRAM-ID.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SORTING.
02 A PIC X(20) OCCURS 10 TIMES.
77 I PIC 9(2).
77 J PIC 9(2).
77 TEMP PIC X(2).
77 N PIC 9(2).
77 C PIC 9(2).
PROCEDURE DIVISION.
PARA.
DISPLAY "SORTING ALPHA NUMERIC DATA".
DISPLAY "ENTER N VALUE".
ACCEPT N.
DISPLAY "ENTER THE ELEMENTS OF ARRAY".
PERFORM GETDATA VARYING I FROM 1 BY 1 UNTIL I > N.
DISPLAY "ARRAY ELEMENTS BEFORE SORTING ".
PERFORM DIS-PARA VARYING I FROM 1 BY 1 UNTIL I > N.
PERFORM SORT-DATA VARYING I FROM 1 BY 1 UNTIL I > N
AFTER J FROM 1 BY 1 UNTIL J > N.
DISPLAY "THE SORTED ELEMENTS".
PERFORM DIS-PARA VARYING I FROM 1 BY 1 UNTIL I > N.
STOP RUN.
GETDATA.
ACCEPT A(I).
DIS-PARA.
DISPLAY A(I).
SORT-DATA.
IF A(I) < A(J)
MOVE A(I) TO TEMP
MOVE A(J) TO A(I)
MOVE TEMP TO A(J).
OUTPUT
SORTING ALPHA NUMERIC DATA
ENTER N VALUE
5
ENTER THE ELEMENTS OF ARRAY
-1 R 3 Y E
ARRAY ELEMENTS BEFORE SORTING
-1
R
3
Y
E
THE SORTED ELEMENTS
-1
3
E
R
Y
LAB 5
IDENTIFICATION DIVISION.
PROGRAM-ID. MATRIX.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MATRIX.
02 R OCCURS 5 TIMES.
03 CL OCCURS 5 TIMES.
04 A PIC S99.
04 B PIC S99.
04 C PIC S99.
04 D PIC S99.
77 M PIC 99.
77 N PIC 99.
77 I PIC 99.
77 J PIC 99.
77 S PIC -99.
PROCEDURE DIVISION.
PARA.
DISPLAY "ENTER THE ARRAY SIZE".
ACCEPT M.
ACCEPT N.
DISPLAY "ENTER THE ELEMENTS OF MATRIX".
PERFORM A-PARA VARYING I FROM 1 BY 1 UNTIL I > M
AFTER J FROM 1 BY 1 UNTIL J > N.
PERFORM B-PARA VARYING I FROM 1 BY 1 UNTIL I > M
AFTER J FROM 1 BY 1 UNTIL J > N.
PERFORM C-PARA VARYING I FROM 1 BY 1 UNTIL I > M
AFTER J FROM 1 BY 1 UNTIL J > N.
DISPLAY (1, 1) ERASE.
DISPLAY (2, 2) "THE RESULT OF MATRIX ADDITION".
MOVE 4 TO LIN.
PERFORM CD-PARA VARYING I FROM 1 BY 1 UNTIL I > M.
DISPLAY (9, 2) "THE RESULT OF MATRIX SUBSTRACTION".
MOVE 11 TO LIN.
PERFORM SD-PARA VARYING I FROM 1 BY 1 UNTIL I > N.
STOP RUN.
A-PARA.
ACCEPT A(I, J).
B-PARA.
ACCEPT B(I, J).
C-PARA.
COMPUTE C(I, J) = A(I, J) + B(I, J).
COMPUTE D(I, J) = A(I, J) - B(I, J).
CD-PARA.
MOVE 5 TO COL.
PERFORM D-PARA VARYING J FROM 1 BY 1 UNTIL J > N.
ADD 3 TO LIN.
D-PARA.
MOVE C(I, J) TO S.
DISPLAY (LIN, COL) S.
ADD 5 TO COL.
SD-PARA.
MOVE 5 TO COL.
PERFORM E-PARA VARYING J FROM 1 BY 1 UNTIL J > N.
ADD 3 TO LIN.
E-PARA.
MOVE D(I, J) TO S.
DISPLAY (LIN, COL) S.
ADD 5 TO COL.
OUTPUT
ENTER THE ARRAY SIZE
2
2
ENTER THE ELEMENTS OF MATRIX
1
1
1
1
2
2
2
2
THE RESULT OF MATRIX ADDITION
03 03
03 03
THE RESULT OF MATRIX SUBSTRACTION
-01 -01
-01 -01
LAB 6
IDENTIFICATION DIVISION.
PROGRAM-ID. MATRIXM.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MATRIX.
02 R OCCURS 5 TIMES.
03 CL OCCURS 5 TIMES.
04 A PIC S9(2).
04 B PIC S9(2).
04 C PIC S9(2).
77 M PIC 99.
77 N PIC 99.
77 I PIC 99.
77 J PIC 99.
77 K PIC 99.
77 S PIC -99.
PROCEDURE DIVISION.
P1.
DISPLAY "ENTER THE SIZE OF ARRAY".
ACCEPT M.
ACCEPT N.
IF M = N
PERFORM MUL-PARA
ELSE
DISPLAY "MATRIX SIZE MUST BE EQUAL".
STOP RUN.
MUL-PARA.
DISPLAY "ENTER THE ELEMENTS OF MATRIX A".
PERFORM A-PARA VARYING I FROM 1 BY 1 UNTIL I > M
AFTER J FROM 1 BY 1 UNTIL J > N.
DISPLAY "ENTER THE ELEMENTS OF MATRIX B".
PERFORM B-PARA VARYING I FROM 1 BY 1 UNTIL I > M
AFTER J FROM 1 BY 1 UNTIL J > N.
PERFORM M-PARA VARYING I FROM 1 BY 1 UNTIL I > M
AFTER J FROM 1 BY 1 UNTIL J > N.
DISPLAY (1, 1) ERASE.
DISPLAY "RESULT OF MATRIX MULTIPLICATION".
MOVE 4 TO LIN.
PERFORM MD-PARA VARYING I FROM 1 BY 1 UNTIL I > N.
A-PARA.
ACCEPT A(I, J).
B-PARA.
ACCEPT B(I, J).
M-PARA.
COMPUTE C(I, J) = 0.
PERFORM C-PARA VARYING K FROM 1 BY 1 UNTIL K > N.
C-PARA.
COMPUTE C(I, J) = C(I, J) + (A(I, K) * B(K, J)).
MD-PARA.
MOVE 5 TO COL.
PERFORM D-PARA VARYING J FROM 1 BY 1 UNTIL J > N.
ADD 1 TO LIN.
D-PARA.
MOVE C(I, J) TO S.
DISPLAY (LIN, COL) S.
ADD 5 TO COL.
OUTPUT
ENTER THE ARRAY SIZE
2
2
ENTER THE ELEMENTS OF MATRIX A
2
2
2
2
ENTER THE ELEMENTS OF MATRIX B
2
2
2
2
RESULT OF MATRIX MULTIPLICATION
08 08
08 08