Algorithm and Flowchart PDF Free
Algorithm and Flowchart PDF Free
ALGORITHM
A. Algorithm Defined
B. Properties of Algorithm
1. Finiteness - there is an exact number of steps to be taken and has an end.
2. Absence of Ambiguity - means that every instruction is precisely described
and clearly specified.
3. Sequence of Execution – instructions are performed from top to bottom.
4. Input and Output - defined the unknowns of the problem is specified and
with the expected outcome.
5. Effectiveness- the solution prescribed is guaranteed to give a correct
answer and that the specified process is faithfully carried out.
6. Scope Definition - applies to a specific problem or class of problem.
1. Pseudocode
D. Examples
1. Write an algorithm to determine a student’s final grade and indicate whether it is
passing or failing. The final grade is calculated as the average of four marks.
Pseudocode:
Input a set of 4 marks
Calculate their average by summing and dividing by 4
if average is below 50
Print “FAIL”
else
Print “PASS”
Detailed Algorithm
Step 1: Input M1,M2,M3,M4
Step 2: GRADE (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
FLOWCHART
A. Flowchart Defined
B. Flowchart Symbols
C. Processing
1. Flow lines
Flow lines with arrowheads are used to indicate the flow of operation, that is, the exact
sequence in which the instructions are to be executed. The normal flow of flowchart is
from top to bottom and left to right. Arrowheads are required only when the normal top
to bottom flow is not to be followed.
1. Decision
The decision symbol is used in a flowchart to indicate a point at which a decision has to
be made and a branch to one of two or more alternative points is possible.
1. Connector
If a flowchart becomes very long, the flow lines start crisscrossing at many places
that causes confusion and reduces the clarity of the flowchart. Moreover, there
are instances when a flowchart becomes too long to fit in a single page and the
use of flow lines becomes impossible. Thus, whenever a flowchart becomes too
complex that the number and direction of flow lines is confusing or it spreads
over more than one page, it is useful to utilize the connector symbol as a
substitute for flow lines. This symbol represents an entry from, or an exit to
another part of the flowchart. A connector symbol is represented by a circle and a
letter or digit is placed within the circle to indicate the link. A pair of identically
labeled connector symbols is commonly used to indicate a continued flow when
the use of a line is confusing
Examples:
1. Draw a flowchart that will accept and display a number. Write its equivalent algorithm.
BEGIN Algorithm
Read A
Step 1. Read in the value of A
2. Draw a flowchart
ENDthat will compute and display the sum and product of two numbers.
Write its equivalent algorithm.
BEGIN Algorithm
END
3. Write an algorithm and draw a flowchart that will read the two sides of a rectangle
calculate and print its area. Formula: Area = Length x Width.
Algorithm
BEGIN
Area = L x W
END
Print
Area
2. Selection - Once the condition is evaluated, the control flows into one of two paths.
Once the conditional execution is finished, the flows rejoin before leaving the structure.
As an alternative, the "Question" could be replaced with a Boolean expression and the
branches labelled END
"TRUE" and "FALSE".
Operators Commonly Used in Flowcharting
A. Arithmetic Operators
Operators Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
B. Relational Operators
Operators Meaning
= Equal
C. Logical Operators
Operator Meaning
&& AND
II OR
! NOT
Examples:
1. Draw a flowchart that will input values for x and y. Compare two values inputted and
print which of the values is higher including the remark “Higher”. Write its equivalent
algorithm.
Algorithm
x>y T
Print x, “Higher”
x>y
Print y, “Higher”
END
2. Draw a flowchart that will determine the student’s final grade and indicate whether it
is passing or failing. The final grade is calculated as the average of four marks.
Algorithm
else
PrintGrade=(M1+M2+M3+M4)/4
“PASS”
F T
IS GRADE<50
Print Print
“Pass” ”Fail”
END
3. JLB Manufacturing Company plans to give a year-end bonus to each of its
employee. Draw a flowchart will compute the bonus of an employee. Consider the
following conditions: If the employee’s monthly salary is less than or equal 10,000
pesos, the bonus is 25% of the salary. If the employee’s monthly salary is greater
than 10,000 pesos, the bonus is 3,000 pesos. Print the name and the corresponding
bonus for each employee. Write the equivalent algorithm.
Algorithm
Bonus = salary * 25 %
Else
Bonus = 3,000
bonus=0
begin
Read Name,
Salary
F
Bonus = 3,000
Salary
< =10,000
T
Bonus = 0.25*Salary
Print Name,
Bonus
en end
dEND
2. Repetition - 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
3.
4.
5.
6. Loops and Counter
7. Looping
8. Used when it is desired to make the same calculation of more than one set of
data. It consists of repeating a program, or a section of program and substituting
new data for each repetition.
9.
10. Counter
11. Is a setup in a program loop to keep track of a number of times the program
segment is repeated. The program can then be terminated after the completion
of a predetermined number of passes.
12.
13. Steps in Loop Control
14. Initialization
15. The value of counter is initially set equal to zero or one.
16.
17. Test for limit condition
18. Before the logic flow gets out of a loop, a loop terminating condition must first be
satisfied.
19. Incrementation
20. Often each loop is executed, 1 is added to the counter. Thus counter reflects the
number of times the operation has been performed.
21.
22.
23. Examples:
24. 1. Construct a flowchart that will count from 1 to 10 and print each number
counted using the looping structure. Write the equivalent algorithm.
25.
26.
Algorithm
Step 3. If N is less than 10, add 1 to the value of N, print the value then
go back to step 2. However, if N is greater than 10, stop
processing.
27.
28.
29.
30.
31.
32.
BEGIN
N=0
F
END
N<10
N=N +1
Print N
33. 2. The initial value of the radius of a circle is equal to 1 unit and each succeeding
radius is 1 unit greater than the value before it. Draw a flowchart to compute the
area of a circle starting with radius=1 up to radius = 5, then print each radius and
the corresponding area of a circle.
34. Formula: area = pi x r2
35.
36.
37.
38.
39.
Algorithm
40.
Step 1. Initialize the value of radius(r) to 1 and the value of pi to 3.1416.
Pi=3.1416 r=1
area=pi * r *r
Print r, area
r=r+1
F
T
end
END
R<5