Algorithms and Flowcharts: Riphah International University I-14 (Islamabad)
Algorithms and Flowcharts: Riphah International University I-14 (Islamabad)
Instructor:
Mr. Tabassum Javed
Faculty of Computing
Riphah International University I-14 (Islamabad)
Flowcharts Pseudocode &
Algorithms
2
Algorithm
• An algorithm is a sequence of steps to
solve a particular problem
3
Characteristics of Algorithm
4
Control Structures
5
Advantages of Algorithm
6
How to write Algorithm
• Step 1:
– Define your algorithms input:
• Step 2:
– Define the variables:
• Step 3:
– Outline the algorithm's operations:
• Step 4:
– Output the results of your algorithm's
operations:
7
Algorithm to find sum of two
numbers
8
Flowcharts
• Diagrammatic /Graphical representation of
sequence of steps to solve a problem.
9
Advantages of Flowcharts
• Flowchart is an excellent way of communicating
the logic of a program.
10
Advantages of Flowcharts
• After successful development of a program, it
needs continuous timely maintenance during the
course of its operation. The flowchart makes
program or system maintenance easier.
11
General Rules of Flowcharts
• All boxes of the flowchart are connected with
Arrows. (Not lines)
• Flowchart symbols have an entry point on the
top of the symbol.
• The exit point for all flowchart symbols is on the
bottom except for the Decision symbol.
• The Decision symbol has two exit points; these
can be on the sides or the bottom and one side.
12
General Rules of Flowcharts
• Generally a flowchart will flow from top to
bottom. However, an upward flow can be shown
as long as it does not exceed 3 symbols.
• Connectors are used to connect breaks in the
flowchart. Examples are:
– From one page to another page.
– From the bottom of the page to the top of the same
page.
13
Flowchart Symbols
14
Basic Flowchart START
Rounded
Rectangle
END
15
Basic Flowchart START Terminal
Multiply Hours
by Pay Rate.
START Store result in
Gross Pay.
Display Gross
Pay
END Terminal
END
16
Basic Flowchart START
17
Basic Flowchart START
computation or variable
Multiply Hours
assignment Process
by Pay Rate.
Store result in
Multiply Hours Gross Pay.
by Pay Rate.
Store result in Display Gross
Pay
Gross Pay.
END
18
Stepping Through
Stepping Through START
Output
Operation
the Flowchart
Flowchart
Display message
the
“How many
hours did you
work?”
Read Hours
How many
hours did
you work?
Display message
“How much do
you get paid per
hour?”
Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.
19
Stepping Through
Stepping Through START
the Flowchart
Flowchart
Display message
the
“How many
hours did you
work?”
Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.
20
Stepping Through
Stepping Through START
the Flowchart
Flowchart
Display message
the
“How many
hours did you
work?”
Read Hours
How much
do you get
paid per
Display message
hour?
“How much do
Output you get paid per
Operation hour?”
Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.
Hours: 40
Display Gross
Pay Rate: ? Pay
21
Stepping Through
Stepping Through START
the Flowchart
Flowchart
Display message
the
“How many
hours did you
work?”
Read Hours
How much
do you get
paid per
Display message
hour? 20
“How much do
you get paid per
hour?”
Hours: 40
Display Gross
Pay Rate: 20 Pay
22
Stepping Through START
Display message
Read Hours
How much
do you get
paid per
Display message
hour?
“How much do
you get paid per
hour?”
Multiply Hours
Process: The by Pay Rate.
Store result in
Variable Contents: product of 40
times 20 is
Gross Pay.
Hours: 40 stored in
Gross Pay Display Gross
Pay Rate: 20 Pay
23
Stepping Through START
the Flowchart
Display message
“How many
hours did you
work?”
Read Hours
Your gross
pay is 800
Display message
“How much do
you get paid per
hour?”
Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.
Hours: 40
Output Display Gross
Pay Rate: 20 Operation Pay
24
Review
Input/Output
Operation Connector
Process Module
26
27