University of Hafr Al-Batin
Hafr Al-Batin Community College ( HBCC )
Computer Science & Engineering Technology Unit (CSET)
CST121: Introduction to Computer
Programming
Flowcharts & Algorithms
Lecture-2
1
Steps in using a computer as
problem solving tool
1. Develop an Algorithm and a Flowchart.
2. Write the program in programming language
(C, C++, JAVA, COBOL, etc.).
3. Enter the program in computer.
4. Test and Debug the program.
5. Run the program, input data, and get the
result from the computer.
2
What is ALGORITHM?
• Definition: Algorithm is a step by step
procedure to solve a problem (Finite steps).
• Algorithms can be expressed by any one of the
following:
a) Pseudo-code: Algorithm written in natural language.
b) Flowchart: Algorithm represented diagrammatically.
3
The Flowchart
• Definition: A graphical representation of the
sequence of operations in an information
system or program.
– Information system flowcharts show how data
flows from source documents through the
computer to final distribution to users.
– Program flowcharts show the sequence of
instructions in a single program or subroutine.
Different symbols are used to draw each type of
flowchart.
4
The Flowchart
A Flowchart
– shows logic of an algorithm
– emphasizes individual steps and their
interconnections
– e.g. control flow from one action to the next
5
Symbols used in Flowcharts
Terminal Symbol:
indicates the starting or stopping point in the logic.
Input/Output Symbol:
Represents an input or output process in an algorithm
Process Symbol:
Represents any single process in an algorithm
Predefined Process Symbol:
Represents any predefined process
Decision Symbol:
Represents a decision in the logic involving the
comparison of two values.
6
Cont…
Flow Lines
The arrow indicates the "direction" of flow.
Annotation Symbol
You can use it to write a note/comment.
In-Page Connector
It is used to join two parts of program on same page.
Also used for goto or jump to some specific point.
Off-Page Connector
Used to connect two parts of flowchart which are on
different pages.
7
The three basic control structures:-
1. Sequence
2. Selection
3. Repetition
8
1. Sequence
Statemement a
Statemement b
Statemement c
9
Example
Problem : Write an algorithm and draw a flowchart for a
program to find the area of a rectangle.
START
Algorithm
Input W, L
• Step 1: Input W, L
• Step 2: A L x W ALxW
• Step 3: Print A
Print A
STOP
10
2. Selection
T F
F Condition p?
Condition p?
T
Statemement a Statemement b
Statemement a
11
Example
Problem : Write an algorithm and draw a flowchart for a program
to find overall grade in four courses, i.e., FAIL if average is less
than 50, PASS otherwise.
START
Input
Algorithm: M1,M2,M3,M4
Step 1: Input M1,M2,M3,M4 GRADE(M1+M2+M3+M4)/4
Step 2: GRADE (M1+M2+M3+M4)/4
Step 3: if (GRADE <50) then
Print “FAIL” N IS Y
GRADE<50
else
Print “PASS”
endif Print “PASS” Print “FAIL”
STOP
12
3. Repetition
F
Condition p?
Statemement block
13
Example
Problem : Write an algorithm and draw a flowchart for steps in
SDLC (Software Development Life Cycle)
Algorithm Flowchart
1. Start
2. Design the Software.
3. Use the Design for Code.
4. Test the Software.
5. If error
If error in Design
Then correct the Design
Else
Correct the Code
6. Stop 14
More examples
• More examples can be found in Lab 1 Material
15