Introduction To Computer Programming Problem Solving & Algorithms
Introduction To Computer Programming Problem Solving & Algorithms
Programming
Problem Solving & Algorithms
Jehangir Arshad Meo
Lec#5
Sahiwal
Flow Charts
A flowchart is a visual or graphical representation of an algorithm.
2
Flowcharts – Most Common Symbols
SymbolName Function
Terminal Represents the beginning or end of a program.
3
Flow Charting
Expresses the flow of processing in a
structured pictorial format.
Flow
Input and Processing of
Output Steps Steps data
Decision Terminator
Connectors
4
Begin
Flow chart for
Converting
Get temp. in ‘F’
Fahrenheit
into Celsius
5
Calculate C(F32
)
9
Print ‘C’
Stop
5
Flow chart for
Get three scores
calculating
Add them together average of
three scores
Divide the result by three
Yes No
More students? Stop
6
Comparison of Algorithm representations in Natural language,
flowchart and Pseudo-code
START
INPUT
Step 1: Begin the calculations A, B
BEGIN Adder
Step 2: Input two values A and B Input A and B
C = A + B
Add A to B
Step 3: Add the values PRINT C
and store in C
END Adder
Step 4: Display the result
END
Natural language Flowchart Pseudo-code
7
Pseudo-code
Computer scientists use pseudo-code to express
algorithms:
English like constructs (or other natural language), but
8
Pseudo-code:
Three basic kind of operations:
Sequential
Computation ( Set … )
Input/Output ( Get ... / Print ... )
Conditional
If … Else
If …
Iterative / looping
Repeat ...
While ...
9
Variables
A variable is a named storage.
- A value can be stored into it, overwriting the
previous value
- Its value can be copied
Examples:
Set the value of A to 3
The variable A holds the value 3 after its execution
Set the value of A to (A+1)
Same as: add 1 to the value of A ( A is now 4)
10
Sequential Operations - Input/Output
Input
Outside world
Output
11
Input
General format:
12
Output
General format:
13
Example
Write an algorithm to calculate the average of three
numbers.
Steps Operations
1 Get values for N1, N2, and N3
2 Set the value of Average to (N1+N2+N3)/3
3 Print the value of Average
4 Stop
14
Conditional Operations
If <condition> then
operations for the then-part
Else
operations for the else-part
15
Conditions, or Boolean Expressions
16