Download presentation
Presentation is loading. Please wait.
Published byHarriet Pitts Modified over 8 years ago
1
General Introduction Algorithms
2
Let’s write a program A program is a collection of statements written in a language the computer understands. A computer executes program statements one after another in sequence until it reaches the end of the program unless some statement in the program alters the order of execution. Let’s write a program to accept two numbers from the user, multiply them together and display the result on the screen. We’ll write the program in COBOL. What COBOL program statements will we need to do the job?
3
Program Statements We need a statement to take in the first number and store it in a named memory location. l l ACCEPT Num1. We need a statement to take in the second number and store it in a named memory location. l l ACCEPT Num2. We need a statement to multiply the two numbers together and store the result in a named location. l l MULTIPLY Num1 BY Num2 GIVING Result. We need a statement to display the result on the screen. l l DISPLAY "Result is = ", Result.
4
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. Program-1 PROGRAM-ID. Program-1. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result Calc-Result. ACCEPT Num1. MULTIPLY Num1 BY Num2 GIVING Result. ACCEPT Num2. DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result 0 0 0 0 00 D ATA
5
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Program-1. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1 ACCEPT Num1. MULTIPLY Num1 BY Num2 GIVING Result. ACCEPT Num2. DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result 9 9 0 0 00 D ATA
6
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Program-1. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1. MULTIPLY Num1 BY Num2 GIVING Result MULTIPLY Num1 BY Num2 GIVING Result. ACCEPT Num2. DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result 9 9 0 0 00 D ATA
7
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Program-1. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1. MULTIPLY Num1 BY Num2 GIVING Result. ACCEPT Num2 ACCEPT Num2. DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result 0 0 5 5 00 D ATA
8
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Program-1. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1. MULTIPLY Num1 BY Num2 GIVING Result. ACCEPT Num2. DISPLAY "Result is = ", Result DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result 9 9 5 5 00 D ATA Oh No!! We got the wrong answer. Let’s try again.
9
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. Program-2 PROGRAM-ID. Program-2. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result Calc-Result. ACCEPT Num1. ACCEPT Num2. DISPLAY "Result is = ", Result. MULTIPLY Num1 BY Num2 GIVING Result. STOP RUN. Num1 Num2 Result 0 0 0 0 00 D ATA
10
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Program-2. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1. ACCEPT Num2. DISPLAY "Result is = ", Result. MULTIPLY Num1 BY Num2 GIVING Result. STOP RUN. Num1 Num2 Result 9 9 0 0 00 D ATA
11
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Program-2. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1. ACCEPT Num2 ACCEPT Num2. DISPLAY "Result is = ", Result. MULTIPLY Num1 BY Num2 GIVING Result. STOP RUN. Num1 Num2 Result 9 9 5 5 00 D ATA
12
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Program-2. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1. ACCEPT Num2. DISPLAY "Result is = ", Result DISPLAY "Result is = ", Result. MULTIPLY Num1 BY Num2 GIVING Result. STOP RUN. Num1 Num2 Result 9 9 5 5 00 D ATA Oh No!! We got the wrong answer again. Let’s have one more try.
13
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Program-2. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1. ACCEPT Num2. DISPLAY "Result is = ", Result. MULTIPLY Num1 BY Num2 GIVING Result MULTIPLY Num1 BY Num2 GIVING Result. STOP RUN. Num1 Num2 Result 9 9 5 5 45 D ATA
14
Num1 Num2 Result $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. Sequence-Program PROGRAM-ID. Sequence-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result Calc-Result. ACCEPT Num1. ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result. STOP RUN. 0 0 0 0 00 D ATA
15
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Sequence-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1 ACCEPT Num1. ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result. STOP RUN. 9 000 Num1 Num2 Result D ATA
16
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Sequence-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1. ACCEPT Num2 ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result. STOP RUN. 9 5 00 Num1 Num2 Result D ATA
17
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Sequence-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1. ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result. STOP RUN. 95 45 Num1 Num2 Result D ATA
18
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Sequence-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. Calc-Result. ACCEPT Num1. ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result DISPLAY "Result is = ", Result. STOP RUN. 95 45 Num1 Num2 Result D ATA Right.. At last!! It’s not enough to know what statements we need. We must make sure the computer executes them in the right order.
19
Sequence. Selection. Iteration. Programs are written using three main programming constructs Programs are written using three main programming constructs.
20
Num1 Num2 Result Operator $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. Selection-Program PROGRAM-ID. Selection-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator Calculator. ACCEPT Num1. ACCEPT Num2. ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF. DISPLAY "Result is = ", Result. STOP RUN. 0 0 0 0 00 D ATA _ _
21
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Selection-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. ACCEPT Num1 ACCEPT Num1. ACCEPT Num2. ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF. DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result Operator 7 7 0 0 00 D ATA _ _
22
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Selection-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. ACCEPT Num1. ACCEPT Num2 ACCEPT Num2. ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF. DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result Operator 7 7 3 3 00 D ATA _ _
23
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Selection-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. ACCEPT Num1. ACCEPT Num2. ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF. DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result Operator 7 7 3 3 00 D ATA + +
24
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Selection-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. ACCEPT Num1. ACCEPT Num2. ACCEPT Operator IF Operator = "+" THEN IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF. DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result Operator 7 7 3 3 00 D ATA + +
25
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Selection-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. ACCEPT Num1. ACCEPT Num2. ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF. DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result Operator 7 7 3 3 10 D ATA + +
26
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Selection-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. ACCEPT Num1. ACCEPT Num2. ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF END-IF. DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result Operator 7 7 3 3 10 D ATA + +
27
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Selection-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. ACCEPT Num1. ACCEPT Num2. ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF. DISPLAY "Result is = ", Result DISPLAY "Result is = ", Result. STOP RUN. Num1 Num2 Result Operator 7 7 3 3 10 D ATA + +
28
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. Iteration-Program PROGRAM-ID. Iteration-Program. AUTHOR. Team SarMag. DATA DIVISION DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. PERFORM 5 TIMES ACCEPT Num1 ACCEPT Num2 ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result END-PERFORM. STOP RUN. D ATA Num1 Num2 Result Operator 0 0 0 0 00 D ATA _ _
29
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Iteration-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. PERFORM 5 TIMES PERFORM 5 TIMES ACCEPT Num1 ACCEPT Num2 ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result END-PERFORM END-PERFORM. STOP RUN. D ATA Num1 Num2 Result Operator 0 0 0 0 00 D ATA _ _
30
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Iteration-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. PERFORM 5 TIMES ACCEPT Num1 ACCEPT Num1 ACCEPT Num2 ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result END-PERFORM. STOP RUN. D ATA Num1 Num2 Result Operator 5 5 0 0 00 D ATA _ _
31
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Iteration-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. PERFORM 5 TIMES ACCEPT Num1 ACCEPT Num2 ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result END-PERFORM. STOP RUN. D ATA Num1 Num2 Result Operator 5 5 3 3 00 D ATA _ _
32
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Iteration-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. PERFORM 5 TIMES ACCEPT Num1 ACCEPT Num2 ACCEPT Operator ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result END-PERFORM. STOP RUN. D ATA Num1 Num2 Result Operator 5 5 3 3 00 D ATA * *
33
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Iteration-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. PERFORM 5 TIMES ACCEPT Num1 ACCEPT Num2 ACCEPT Operator IF Operator = "+" THEN IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result END-PERFORM. STOP RUN. D ATA Num1 Num2 Result Operator 5 5 3 3 00 D ATA * *
34
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Iteration-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. PERFORM 5 TIMES ACCEPT Num1 ACCEPT Num2 ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result END-PERFORM. STOP RUN. D ATA Num1 Num2 Result Operator 5 5 3 3 00 D ATA * *
35
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Iteration-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. PERFORM 5 TIMES ACCEPT Num1 ACCEPT Num2 ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result END-PERFORM. STOP RUN. D ATA Num1 Num2 Result Operator 5 5 3 3 15 D ATA * *
36
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Iteration-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. PERFORM 5 TIMES ACCEPT Num1 ACCEPT Num2 ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result DISPLAY "Result is = ", Result END-PERFORM. STOP RUN. D ATA Num1 Num2 Result Operator 5 5 3 3 15 D ATA * *
37
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Iteration-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. PERFORM 5 TIMES ACCEPT Num1 ACCEPT Num1 ACCEPT Num2 ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result END-PERFORM. STOP RUN. D ATA Num1 Num2 Result Operator 9 9 3 3 15 D ATA * *
38
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Iteration-Program. AUTHOR. Team SarMag. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. 01 Operator PIC X VALUE SPACE. PROCEDURE DIVISION. Calculator. PERFORM 5 TIMES ACCEPT Num1 ACCEPT Num2 ACCEPT Operator IF Operator = "+" THEN ADD Num1, Num2 GIVING Result END-IF IF Operator = "*" THEN MULTIPLY Num1 BY Num2 GIVING Result END-IF DISPLAY "Result is = ", Result END-PERFORM. STOP RUN. D ATA Num1 Num2 Result Operator 9 9 3 3 15 D ATA * *
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.