Algorithms and Flowcharts 2
Algorithms and Flowcharts 2
Algorithms and Flowcharts 2
FLOWCHARTING II
LOOPS
Computers are particularly well suited to
applications in which operations are
repeated many times.
If the same task is repeated over and over
again a loop can be used to reduce
program size and complexity
Flowchart
START
Base2
Product Base
Product Product * Base
Product Product * Base
Product Product * Base
Print
Product
STOP
Algorithm:
Base 2
Power 4
Product Base
Counter 1
While Counter < Power
Repeat Step 5 through step 7
Step 6: Product Product * Base
Step 7: Counter Counter +1
Step 8: Print Product
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
START
Base 2
Power 4
Product Base
Counter 1
is
Counter < Power
Y
Product Product * Base
Counter Counter + 1
Print
Product
STOP
TRACING
BASE POWER PRODUCT COUNTER COUNTER < POWER
STEP 1:
STEP 2:
STEP 3:
STEP 4:
STEP 5:
STEP 6:
STEP 7:
STEP 5:
STEP 6:
STEP 7:
STEP 5:
STEP 6:
STEP 7:
STEP 5:
2
2
2
2
2
2
2
2
2
2
2
2
2
2
STEP 8:
?
4
4
4
4
4
4
4
4
4
4
4
4
4
16.
?
?
2
2
2
2x2=4
4
4
4x2=8
8
8
8x2=16
16
16
?
?
?
1
1
1
1+1=2
2
2
2+1=3
3
3
3+1=4
4
?
?
?
T
T
T
T
T
T
T
T
T
F
F
Step 1:
Base 2
Step 2: Power 4
Step 3:
Product Base
Step 4: Counter 1
Step 5: While Counter < Power
Repeat Step 5 through
step 7
Step 6: Product Product *
Base
Step 7: Counter Counter +1
Step 8: Print Product
Algorithm
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Input N1
Max N1
Input N2
If (N2>Max) then
Max = N2
endif
Input N3
If (N3>Max) then
Max = N3
endif
Print The largest number is:,Max
Flowchart &
Tracing
N1
N2
N3
Step1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Algorithm:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:
Step 9:
Input N
Input Current
Max Current
Counter 1
While (Counter < N)
Repeat steps 5 through 8
Counter Counter + 1
Input Next
If (Next > Max) then
Max Next
endif
Print Max
START
Input
N, Current
Max Current
Counter 1
Counter < N
Print
Max
Counter Counter +1
Input
Next
STOP
Next
>Max
Y
Max Next
Tracing
Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7
Step 8
Step 5
Step 6
Step 7
Step 8
Step 5
Step 6
Step 7
Step 8
Step 5
Step 6
Step 7
Step 8
Step 5
Step 9
Current
Max
Counter
Counter < N
Next
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
4
4
4
4
4
4
4
4
6
6
6
6
8
8
1
1
2
2
2
2
3
3
3
3
4
4
4
4
5
5
5
5
T
T
T
T
T
T
T
T
T
T
T
T
T
T
F
F
F
F
4
4
4
4
2
2
2
2
6
6
6
6
8
8
8
T
F
F
F
F
F
F
T
T
F
F
T
T
F
8 output
---- 12 6 = 72
---- 1 1 = 1, 1 2 = 2,
---- 2 1 = 2, 2 2 = 4,
1 12 = 12
2 12 = 24
12 12 = 144