You are on page 1of 30

COMP.

1 : COMPUTER FUNDAMENTALS AND


PROGRAMMING

ALGORITHMS AND
FLOWCHARTS
by: eestrellado2024
ALGORITHMS AND FLOWCHARTS
 A typical programming task can be divided into
two phases:
 Problem solving phase
 produce an ordered sequence of steps that describe
solution of problem
 this sequence of steps is called an algorithm

 Implementation phase
 implement the program in using suitable programming
languages
Steps in Problem Solving

Create a step by step instructions (detailed


algorithm) that is very close to a computer
language.

ALGORITHM – self contained step by step set of


operations to be performed by computer.
The Flowchart
 A graphical representation of the
sequence of operations in an information
system or program.
 Information system flowcharts shows how
data flow from source documents through
the computer to final distribution to users
using different symbols.
 shows logic of an algorithm
Flowchart Symbols
Symbols NAME Description

OVAL TERMINAL/ Denotes the beginning


TERMINATOR and end of the program

Parallelogram Input/output Denotes an input and


output data

Rectangle Process Denotes a process to be


carried out

Diamond Decision Symbol Denotes a decision to


be made (e.g. IF –
THEN-ELSE Statement
Arrow Flow lines Denotes the direction or
logic flow of the program
EXAMPLE
IN WRITING AN ALGORITHM
AND DRAWING A
FLOWCHART
Writing an Algorithm & draw a
flowchart
 Example 1: Write an algorithm and draw a
flowchart to determine a student’s final
grade. The final grade is calculated as the
average of two exams: midterm and final
exam.
ALGORITHM

Step 1: Input M, F

Step 2: FG = (M + F)/2

Step 3: PRINT/DISPLAY FG

Note: M = Midterm
F = Finals
2 = two terms
ALGORITHM FLOWCHART
Step 1: Input M, F

Step 2: FG = (M + F)/2

Step 3: PRINT/DISPLAY FG

Note: M = Midterm
F = Finals
2 = two terms
Writing an Algorithm & draw a
flowchart
 Example 2: Write an algorithm and draw a
flowchart, that will compute the sum of
three even numbers.
 Let X = 1st even number

Y = 2nd even number


Z = 3rd even number
Where (X = 14, Y= 20, Z= 34).
ALGORITHM
Step 1: Input X=14, Y=20, Z=34

Step 2: SUM = 14+20+34

Step 3: PRINT/DISPLAY
 SUM = 68
ALGORITHM FLOWCHART

START
Step 1: Input X=14, Y=20, Z=34

Step 2: SUM = 14+20+34 Input X=14,Y=20,Z=34

Step 3: PRINT/DISPLAY
 SUM = 68
SUM = 14+20+34

SUM = 68

END
Problem #3
(WITH DECISION SYMBOL)
Example 3: Write an algorithm and draw a
flowchart to determine a student’s final
grade and indicate a remarks whether it is
“PASSED” or “FAILED” grade. The final
grade is calculated as the average of four
marks.
EXAMPLE: Find the average of :
Q1, Q2,Q3, Q4
 In this example we are going to validate
the result using IF Function or IF
statement , so decision symbol will be use.
 An IF statement can have two results. The
first result is if your comparison is True, the
second if your comparison is False.

 IF statement/logical statement is defined as


a function which “checks whether a condition
is met, returns one value if True and another
value if it is False”.
 IF, THEN, ELSE. If something is true,
then do this, else/otherwise do that.

For example, if it’s raining, then close the


windows, else/otherwise leave the
windows open.
Problem #3
(WITH DECISION SYMBOL)
Example 3: Write an algorithm and draw a
flowchart to determine a student’s
AVERAGE, then Indicate a remarks
whether the average is a “PASSED” ora
“FAILED” grade. The final grade is
calculated as the average of four marks.
EXAMPLE: Find the average of :
Q1, Q2,Q3, Q4
Algorithm
 Detailed Algorithm
 Step 1: Input Q1=80, Q2, Q3, Q4
Step 2: A = (80 + 85 + 83 + 90) /4
3 DISPLAY A = 84.5
Step 4: If (A > 74) then
Print “PASSED”
else
Print “FAILED”
end If
Example Flowchart START

Input
Q1=80,Q2=83,Q3=85,Q4=90

A = (80+83+85+90) /4

Display A= 84.5

Y IF N
A >74

PRINT PRINT
“PASSED” “FAILED”

END
Algorithm
 Detailed Algorithm
 Step 1: Input L=80, M=87, N=85, O=90
Step 2: FG = (80+87+85+90) /4
FG = 85.5
Step 3: If (GRADE < 75) (NO) then
Print “FAILED”
else
Print “PASSED”
end If
Example Flowchart
START

Input
L=80, M=87, N=85, O=90

FG = (80+87+85+90) /4

FG = 85.5

NO IF
FG<75

PRINT
“PASSED”

END
Algorithm
 Detailed Algorithm
 Step 1: Input L=67, M=67, N=65, O=60
Step 2: FG = (67+67+65+60) /4
FG = 64.75
Step 3: If (GRADE < 75) (YES) then
Print “FAILED”
else
Print “PASSED”
end If
Example Flowchart
START

Input
L=67, M=67, N=65, O=60

FG = (67+67+65+60) /4

FG = 64.75

IF YES
FG<75

PRINT
“FAILED”

END
DECISION STRUCTURES
 The expression A>B or A< B is a logical
expression
 it describes a condition we want to test
 if A>B is true (if A is greater than B) we take
the action to the right, display/print the result for
the value of A and display the “remarks”
 if A>B is false (if A is not greater than B) we
take the action to the right, display/print the
result for the value of B and display the
“remarks”
DECISION STRUCTURES
Structure:

Y is
N
A>B

Print A Print B
IF–THEN–ELSE STRUCTURE
 The structure is as follows
If condition is TRUE display “remarks”
else
FALSE display “remarks”

endif
IF–THEN–ELSE STRUCTURE
 The algorithm for the flowchart is as
follows:
If A>B then
Y N
print A is
A>B

else
print B Print A Print B

endif
Relational Operators

Operator Description
> Greater than

< Less than

= Equal to

 Greater than or equal to

 Less than or equal to

 Not equal to
Assignment : 4 Problems
Write the algorithm and
graphical representation using
flowchart symbols
Your answer should be in MS
Excel
Ass:Write an algorithm and
draw a flowchart: that will
compute the volume of a sphere
References:
 http://www.yspuniversity.ac.in/cic/algorithm-manual.pdf

 https://byjus.com/maths/even-numbers/#:~:text=What%20is%20an
%20Even%20Number,%2C%2012%2C%2014%2C%2016.

 https://corporatefinanceinstitute.com/resources/excel/study/excel-if-
statement/#:~:text=The%20IF%20statement%20is%20a,of%20code
%20evaluates%20to%20FALSE.

 https://engineerstutor.com/2020/10/08/solved-assignment-problems-
algorithms-and-flowcharts/

You might also like