0% found this document useful (0 votes)
177 views32 pages

1 Algorithm Pseudocode Flowchart

This document provides an introduction to algorithms and pseudocode. It defines an algorithm as a list of step-by-step instructions to complete a process. Algorithms can be expressed in pseudocode, which uses plain English to describe the program logic, or in a flowchart, which uses graphic symbols. The document presents several examples of algorithms expressed in pseudocode and flowcharts to demonstrate sequential, conditional, and iterative operations. It also discusses the advantages of using flowcharts and common notations used in flowcharting.

Uploaded by

Daniel
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
177 views32 pages

1 Algorithm Pseudocode Flowchart

This document provides an introduction to algorithms and pseudocode. It defines an algorithm as a list of step-by-step instructions to complete a process. Algorithms can be expressed in pseudocode, which uses plain English to describe the program logic, or in a flowchart, which uses graphic symbols. The document presents several examples of algorithms expressed in pseudocode and flowcharts to demonstrate sequential, conditional, and iterative operations. It also discusses the advantages of using flowcharts and common notations used in flowcharting.

Uploaded by

Daniel
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 32

ES 1 ECE

ALGORITHM
(PSEUDOCODE &
FLOWCHART)
INTRODUCTION

We have to write a computer program to make a


computer do anything. To write a computer
program, you have to tell the computer, step by
step, exactly what you want it to do. The computer
then "executes" the program, following each step
mechanically, to accomplish the end goal.
What is an Algorithm?
• A list of instructions for carrying out a
process step-by-step. Algorithm is a
natural language and NOT a
programming language.
• A recipe in a cookbook is an excellent
example of an algorithm.
Example #1
Let's say that you
have a friend arriving
at the airport, and
your friend needs to
get from the airport
to your house.
Here are four
different algorithms
that you might give
your friend for
getting to your
home:
Example #2

Changing a Flat Tire


1. Jack up the car.
2. Unscrew the lugs.
3. Remove the wheel.
4. Put on the spare.
5. Screw on the lugs.
6. Jack the car down.
Three Categories of Algorithmic Operations

1. sequential operations - instructions are


executed in order.
2. conditional ("question asking") operations -
a control structure that asks a true/false
question and then selects the next
instruction based on the answer.
3. iterative operations (loops) - a control
structure that repeats the execution of a
block of instructions.
Two Kinds of Algorithm

1. Pseudocode - is a simple way of writing programming code


in English. Pseudocode is not actual programming
language. It uses short phrases to write code for programs
before you actually create it in a specific language.
2. Flowchart - is a diagrammatic representation of sequence
of logical steps of a program. Flowcharts use simple
geometric shapes to depict processes and arrows to show
relationships and process/data flow.
Pseudocode
Example #1
Create a program that add 2 numbers together
and then display the result.

This is a sequential operation.

1. Start Program
2. Enter two numbers, A, B
3. Add the numbers together
4. Print Sum
5. End Program
Example #2
Compute the area of a rectangle.

1. Start Program
2. Get the length, l, and width, w
3. Compute the area = l*w
4. Display the area
5. End Program
Example #3
Compute the perimeter of a rectangle.

1. Enter length, l
2. Enter width, w
3. Compute Perimeter = 2*l + 2*w
4. Display Perimeter of a rectangle
Example #4
Computing Sales Tax: Pseudocode the task of computing
the final price of an item after figuring in sales tax.

Note the three types of instructions: input (get),


process/calculate (=) and output (display)

1. get price of item


2. get sales tax rate
3. sales tax = price of item times sales tax rate
4. final price = price of item plus sales tax
5. display final price
6. halt
Example #5
Compute the Weekly Wages of an employee base on the following:
Gross pay depends on the pay rate and the number of hours worked
per week. However, if you work more than 40 hours, you get paid
time-and-a-half for all hours worked over 40. Pseudocode the task of
computing gross pay given pay rate and hours worked.
Solution below is an example with conditional operations.
1. get hours worked
2. get pay rate
3. if hours worked ≤ 40 then
3.1. gross pay = pay rate times hours worked
4. else
4.1. gross pay = pay rate times 40 plus 1.5 times pay rate
times (hours worked minus 40)
5. display gross pay
6. halt
Example #6
Computing a Quiz Average: Pseudo-code a routine to
calculate your quiz average.
This is an example of an Iterative operation (Loop)

1. get number of quizzes


2. sum = 0
3. Count = 0
4. while count < number of quizzes
4.1. get quiz grade
4.2. sum = sum + quiz grade
4.3. count = count + 1
5. average = sum / number of quizzes
6. display average
7. halt
Common Action Keywords
Several keywords are often used to indicate
common input, output, and processing operations.

Input: READ, OBTAIN, GET, ENTER


Output: PRINT, DISPLAY, SHOW
Compute: COMPUTE, CALCULATE, DETERMINE
Initialize: SET, INIT
Add one: INCREMENT, BUMP
Flowchart
Flowchart Symbols
Connectors on the same page
Connectors on different page
Guidelines for Developing Flowcharts
On-page connectors are referenced using numbers.
Off-page connectors are referenced using alphabets.
General flow of processes is top to bottom or left to right.
Flowchart can have only one start and one stop symbol.
Arrows should not cross each other.
Should be clear, neat and easy to follow. No room for ambiguity in
understanding the flowchart.
Only one flow line should come out from a process symbol.
Ensure that the flowchart has a logical start and finish.
It is useful to test the validity of the flowchart by passing through it with
a simple test data.
Advantages of Using Flowcharts
1.Communication: Flowcharts are better way of communicating
the logic of a system to all concerned.
2.Effective analysis: With the help of flowchart, problem can be
analyzed in more effective way.
3.Proper documentation: Program flowcharts serve as a good
program documentation, which is needed for various purposes.
4.Efficient Coding: The flowcharts act as a guide or blueprint
during the systems analysis and program development phase.
5.Proper Debugging: The flowchart helps in debugging process.
6.Efficient Program Maintenance: The maintenance of operating
program becomes easy with the help of flowchart. It helps the
programmer to put efforts more efficiently on that part.
Notations Commonly Used in Flowcharting
Example #1 – Sequential Operation
Make a flowchart for Example A about pseudocode lesson.
Examine and analyze the flowchart below.
Example #2 – Sequential Operation
Construct a flowchart that will allow the user to enter
2 numbers. Compute and display the average.
Example #3 – Sequential Operation
Draw a flowchart that will compute and display for the
area of a circle.
Example #4 – Conditional Operation

Draw a flowchart
that will Input two
numbers then
display and print
the larger number.
Example #5 – Conditional Operation
Draw a flowchart
that will compute
the average of
three test scores
of a student.
If the average is
greater than or
equal to 95,
congratulate the
student.
Example #6 – Conditional Operation
Draw a flowchart that will input your grade score then
display the letter grade assigned by the end user. Table
below shows the assigned letter grade for each test score.
Example #6 – Conditional Operation
Continued…
Example #7 – Iterative Operation
Draw a flowchart that will print numbers from 1 to 10.
Thank you for listening!
Any questions??

You might also like