0% found this document useful (0 votes)
79 views

ITC Lect 06 (Algorithms Flowcharts Pseudocode-I)

The document discusses different ways to represent algorithms, including natural language, flowcharts, and pseudocode. It provides examples of a flowchart and pseudocode to calculate the average grade for a class. Key steps in the flowchart include getting test scores, adding them, dividing by three to get the average, and repeating for each student. Pseudocode offers a structured alternative to natural language to describe algorithms in a more precise yet readable way.

Uploaded by

sayed Tamir jan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

ITC Lect 06 (Algorithms Flowcharts Pseudocode-I)

The document discusses different ways to represent algorithms, including natural language, flowcharts, and pseudocode. It provides examples of a flowchart and pseudocode to calculate the average grade for a class. Key steps in the flowchart include getting test scores, adding them, dividing by three to get the average, and repeating for each student. Pseudocode offers a structured alternative to natural language to describe algorithms in a more precise yet readable way.

Uploaded by

sayed Tamir jan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lecture 06:Algo.

Flowcharts Pseudocode CS 101: Introduction to Computing

Algorithms Flowcharts Pseudocode

Dr. Zahid Halim

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


Lecture 06:Algo. Flowcharts Pseudocode CS 101: Introduction to Computing

Calculate and print the average grade of 3


tests for the entire class
• Input
– 3 test scores for each student
• output
– Average of 3 tests for each student
• Process
1. Get three scores
2. Add them together
3. Divide by three to get the average
4. Print the average
5. Repeat step 1 to 4 for next student
6. Stop if there are no more students

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


Lecture 06:Algo. Flowcharts Pseudocode CS 101: Introduction to Computing

Flow Charts

 A flowchart is a visual or graphical representation of an


algorithm.
 The flowchart employs a series of blocks and arrows,
each of which represents a particular operation or step
in the algorithm.
 The arrows represent the sequence in which the
operations are implemented.

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


Lecture 06:Algo. Flowcharts Pseudocode CS 101: Introduction to Computing
Flowcharts – Most Common Symbols
Symbol Name Function

Terminal Represents the beginning or end of a


program.
Flow-line Represents the flow of logic.

Process Represents calculations or data


manipulation.

Input/Output Represents inputs or outputs of data


and information.

Decision Represents a comparison, question,


or decision that determines
alternative paths to be followed.

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


Lecture 06:Algo. Flowcharts Pseudocode CS 101: Introduction to Computing

Flowcharts – An Example
Find the solution of a quadratic equation
Ax2+Bx+C=0, given A, B and C.
A
START

INPUT X1 = (-B+R)/(2A)
A, B, C X2 = (-B-R)/(2A)

Calculate
PRINT
R = SQRT(B2-4AC) A, B, C, X1, X2

A
END

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


Lecture 06:Algo. Flowcharts Pseudocode CS 101: Introduction to Computing

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
OUTPUT
Step 5: End the calculation
C

END
Natural language Flowchart Pseudo-code
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Lecture 06:Algo. Flowcharts Pseudocode CS 101: Introduction to Computing

Algorithm Representation
(Natural Languages)

• English or some other natural language.


• Are not particularly good:
– too verbose
– unstructured
– too rich in interpretation (ambiguous)
– imprecise

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


Lecture 06:Algo. Flowcharts Pseudocode CS 101: Introduction to Computing

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 ) { …

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


Lecture 06:Algo. Flowcharts Pseudocode CS 101: Introduction to Computing

Pseudo-code

•  Pseudo-code
• Computer scientists use pseudo-code to express algorithms:
– English like constructs (or other natural language), but
– modeled to look like statements in typical programming languages.

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


Lecture 06:Algo. Flowcharts Pseudocode CS 101: Introduction to Computing

Pseudo-code Primitives

Three basic kind of operations:


• Sequential
– Computation ( Set … )
– Input/Output ( Get ... / Print ... )
• Conditional
– If … Else
– If …
• Iterative / looping
– Repeat ...
– While ...

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi

You might also like