ITC Lec06 Algorithms Flowcharts Pseudocode-I
ITC Lec06 Algorithms Flowcharts Pseudocode-I
Saima Jabeen
Last time
Computer programming
Programming languages
Algorithm
Today
Algorithms - Examples
Flowcharts
Input
output
Process
1.
2.
3.
4.
5.
6.
Flow Charts
A flowchart is a visual
representation of an algorithm.
or
graphical
Symbol Name
Terminal
Flow-line
Process
Represents the
of a program.
Represents the
flow of logic.
Input/Output
Decision
beginning or end
Represents a comparison,
question, or decision that
determines alternative paths to be
followed.
5
Flowcharts An Example
Find the solution of a quadratic equation
Ax2+Bx+C=0, given A, B and C.
START
INPUT
A, B, C
Calculate
R = SQRT(B2-4AC)
X1 = (-B+R)/(2A)
X2 = (-B-R)/(2A)
PRINT
A, B, C, X1, X2
END
INPUT
A, B
Add A to B
and store in C
BEGIN Adder
Input A and B
C=A+B
PRINT C
END Adder
OUTPUT
C
END
Natural language
Flowchart
Pseudo-code
7
Algorithm Representation
(Natural Languages)
English or some other natural language.
too verbose
Unstructured
imprecise
Algorithm Representation
(Using Programming Language)
{
int I, m, Carry;
int a[100], b[100], c[100];
cin >> m;
for ( int j = 0 ; k <= m-1 ; j++ ) {
cin >> a[j];
cin >> b[j];
}
Carry = 0;
i = 0;
while ( i < m ) {
Pseudo-code
Pseudo-code = English but looks like programming
Good compromise
Simple, readable, no rules, don't worry about punctuation. Lets
you think at an abstract level about the problem.
Contains only instructions that have a well-defined structure and
resemble programming language
10
Pseudo-code Primitives
Three basic kind of operations:
Sequential
Computation ( Set )
Input/Output ( Get ... / Print ... )
Conditional
If Else
If
Iterative / looping
Repeat
While ...
11