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

Algorithms and Flowcharts

The document discusses algorithms and flowcharts, explaining that algorithms are a set of instructions to solve a problem or represent a calculation, and can be written in many formats including natural language, pseudocode, or programming languages. It provides examples of different types of algorithms using conditional branching, loops, and other programming structures, and how they can be represented visually with flowcharts.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Algorithms and Flowcharts

The document discusses algorithms and flowcharts, explaining that algorithms are a set of instructions to solve a problem or represent a calculation, and can be written in many formats including natural language, pseudocode, or programming languages. It provides examples of different types of algorithms using conditional branching, loops, and other programming structures, and how they can be represented visually with flowcharts.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Algorithms and flowcharts

Algorithms
An algorithm is a set of instructions sequenced to solve a problem or to
represent a calculation. Some would say that an algorithm is basically a
data or program flowchart without the boxes. It is actually a list of
precise steps.

The order in which these steps are carried out is always crucial to the
way an algorithm works. We start at the first line of the algorithm and
work downwards to the final instruction.
Algorithms can be written in many different ways, including everyday
natural language, pseudocode, flowcharts or programming languages.

Programming languages are primarily intended for converting


algorithms to a form that can be understood and executed by a
computer.
Algorithms
• Any algorithm consists of statements which have linear progression,
that is the result of one statement is used in the statements that
follow. It may also contain
• conditional branching, such as IF…THEN…ELSE or CASE…ENDCASE,
which results in a decision being made between two or more courses
of actions.
• It will probably also involve the use of loops such as WHILE…
ENDWHILE or REPEAT…UNTIL. A loop is a sequence of statements
that are repeated a number of times.
Key actions that are performed
• inputting data: INPUT or READ
• outputting data: WRITE or PRINT
• calculation: +, -, *, / (what is the order of arithmetical operations in an
equation)
• Comparison operators: >, <, =, <>
• setting values: ←
Writing an algorithm
X ← 42
means we want to store the number 42 in X.

Z←W+X+Y
• This assigns the result of adding the contents of W, X and Y together
and stores the result of this calculation in Z.
Algorithm to multiply two numbers on a
calculator

Or can be written as
Conditional branching (IF…THEN…ELSE)
• This is sometimes referred to as selection. Conditional branching
means that certain statements are carried out depending on the value
stored within a particular variable name. There are generally
considered to be two types, which are IF…THEN…ELSE and CASE…
ENDCASE.
IF…THEN…ELSE
Exercise: Write an Algorithm using
IF..THEN..ELSE
Consider an exam system where if a student gains 75 or more marks
they are awarded a distinction; if they get between 60 and 74 marks
they are awarded a merit; between 40 and 59 marks the student is
awarded a pass; otherwise they fail the course.
Exercise
Write an algorithm using IF…THEN…ELSE condition, which would input
10 exam marks and if the AVERAGE mark is greater than 50 the output
would be ‘You have passed’. If it was not, then the output would be
‘You have not reached the pass mark’.
Example
Exercise
Write an algorithm that inputs two numbers, checks to see if the
second number is bigger than the first or otherwise, divides bigger
number by smaller numbers and outputs the answer.
CASE…ENDCASE
• With this type of condition, depending on the value input, the
algorithm carries out one of a number of statements.
Example which includes an OTHERWISE
statement.
Loops
• A loop is a sequence of repeated statements that are carried out a
number of times.
WHILE…ENDWHILE
An example of a WHILE…ENDWHILE
algorithm
Question
• Write an algorithm using WHILE…ENDWHILE conditions, which would
input 10 exam marks and if the mark was greater than 40 the output
would be ‘You have passed’. If it was not, then the output would be
‘You have not reached the pass mark’.
REPEAT…UNTIL
Example
Central-heating systems: Steps Involved
1- User enters required temperature using keypad/ touchscreen
2- Microprocessor stores required temperature as a pre-set value
3- Microprocessor receives temperature from sensor
4- Microprocessor compares temperature from sensor to pre-set value
5- If temperature from the sensor is lower than the value, the
microprocessor sends a signal to an actuator to open the gas valves
6- If temperature from the sensor is lower than the pre-set value, the
microprocessor sends a signal to an actuator to switch the pump on
7- If temperature is higher than or equal to the preset value the
microprocessor sends a signal to switch the pump off and close the
valves
8 - This sequence is repeated until the system is switched off
Flowchart describing the processing carried out
by the microprocessor in a central heating
system
Common Symbols
The flowchart to add up five numbers
Task 1
• Draw a flowchart which will allow the average of six numbers to be
calculated.
• Write out the steps in the operation of an air-conditioning system,
putting each distinct step on a separate line.
• Draw a flowchart for an air-conditioning system which could describe
the processing carried out by the microprocessor, assuming the pre-
set (required) temperature has already been input to the system.

You might also like