Introduction To Algorithm & Flowchart - L1
Introduction To Algorithm & Flowchart - L1
FLOWCHART
PREPARATION/
-SIGNIFIES THE PREPARATION
INITIALIZATION OF DATA
-USED TO SELECT INITIAL
CONDITIONS
PERFROMS ANY
PROCESS CALCULATIONS THAT ARE TO
BE DONE
PERFROMS ANY
CALCULATIONS THAT ARE TO
BE DONE
OFF-PAGE
CONNECTOR
FLOWLINES
Basic Control Structures
SEQUENCE- process is executed from one to another in a
straightforward manner.
Example:
Design a flowchart that will accept and display a number.
Write its equivalent algorithm.
START
ALGORITHM:
READ N 1. READ IN THE VALUE OF N.
2. PRINT THE VALUE OF N.
PRINT N
END
Example:
Draw a flowchart that will compute and display the sum
and product of two numbers. Write its equivalent
algorithm.
ALGORITHM:
1. INITIALIZE SUM AND PRODUCT INTO 0.
START 2. READ IN THE VALUES OF A AND B.
3. COMPUTE SUM BY ADDING A AND B THEN
SUM=0 COMPUTE PRODUCT BY MUTIPLYING A AND B.
PRODUCT=0 4. PRINT THE COMPUTED VALUE OF SUM AND
PRODUCT.
READ A, B
A
T
F
B
Example:
F
PRINT Name,
Remarks=“Failed” Grade, END
Remarks
Basic Control Structures
Repetition (Looping)
Do-while-this structure provides for the repetitive execution of
an operation or routine while the condition is true. As long as
the condition is true, the process is executed.
C F
T
Example:
START ALGORITHM
STEP 1: INITIALIZE THE VALUE
OF C TO 0
C=0
STEP 2: TEST IF C IS LESS THAN
10
F STEP 3: IF C IS LESS THAN 10,
C<10 END
ADD 1 TO THE VALUE OF C,
T PRINT THE VALUE THEN GO
BACK TO STEP 2. HOWEVER, IF
C=C+1
C IS GREATER THAN 10, STOP
PROCESSING.
PRINT C
Exercise:
1. Construct a flowchart that will convert an inputted
number in Fahrenheit to its equivalent measure in
Celsius. Formula: C=(5/9) x (F-32)
2. Draw a flowchart that will input values for A and B.
Compare two values inputted and print which of the
values is higher including the remark “Higher”.
Write its equivalent algorithm.
3. Create a flowchart that will accept 10 and 20 as
input and print the sum of the two numbers
Solution for problem #1
START
ALGORITHM:
C=0 1. Initialize C = 0 and F = 0
F=0
2. Read F
ENTER F 3. Compute Celsius(C) using
C=(5/9)x(F-32)
Compute Celsius
C=(5/9)x(F-32) 4. Display Celsius(C)
Display
Celsius(C)
END
Solution for problem #2
START
ALGORITHM:
A=0, B=0, Read A
1. Initialize A=0, B=0 and
Remarks and B Remarks
2. Read A and B
Display
A
Is 3. Compare values of A and
A>
“A is Yes B? B.
Higher”
No
4. If A is higher than B then
display A with a "Higher"
Display B remark, else display B
“B is Higher”
with a "Higher" remarks.
END
Solution for problem #3
START
ALGORITHM:
Sum=0 1. Initialize sum = 0
2. Enter the numbers (10
Enter 10, 20 and 20)
3. Add them and store the
Sum = 10 + 20
result in sum
4. Print sum
Print sum
END