100% found this document useful (1 vote)
1K views

Flowcharts and Pseudocode Exercises

This document discusses flowcharts and pseudocode. It provides examples of flowcharts for making a cup of tea and calculating grades. It also lists keywords used in pseudocode, such as INPUT, OUTPUT, IF/ELSE, and FOR/ENDFOR. Finally, it prompts the reader to write pseudocode for problems like adding numbers, calculating grades from marks, displaying numbers, finding the largest of three numbers, and sorting numbers.

Uploaded by

hakimu
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
100% found this document useful (1 vote)
1K views

Flowcharts and Pseudocode Exercises

This document discusses flowcharts and pseudocode. It provides examples of flowcharts for making a cup of tea and calculating grades. It also lists keywords used in pseudocode, such as INPUT, OUTPUT, IF/ELSE, and FOR/ENDFOR. Finally, it prompts the reader to write pseudocode for problems like adding numbers, calculating grades from marks, displaying numbers, finding the largest of three numbers, and sorting numbers.

Uploaded by

hakimu
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

Flowchart & Pseudocode Exercises

EDU2008 – Introduction to Programming


Hakim Usoof
[email protected]

UNIVERSITY
OF
PERADENIYA
Flowcharts

• Different shapes indicate steps in the


model
• Arrow lines indicate flow

UNIVERSITY
OF
PERADENIYA
Example 1

• Draw a Flowchart to describe the process of preparing a cup of


tea.
– First define the steps
• Boil Water
– Fill kettle with water
– Place kettle on stove
– Waite for water to boil
– Turn off stove
• Empty pot
• Put tea leaves into pot
• Pour boiling water
• Waite 4-5 min for tea to brew
UNIVERSITY • Pour tea
OF

– Next draw flowchart


PERADENIYA
Start Boil Water

Start
Boil Water

Fill Kettle with


Empty Pot water

Put tea leaves Place Kettle


in on Stove

Pour in boiling Waite till


water water boils

Wait for Tea to


Brew Turn off stove

Pour Tea
Stop
UNIVERSITY
OF
PERADENIYA
Stop
Activity

Draw flowcharts for the following scenario


1. Add 2 numbers
2. Calculate grades
– A: mark > 80
– B: 80>mark>65
– C:65>mark>50
– D: 50>mark>40
– F: 40>mark
3. Display numbers from 1 to 10
4. Find the largest among 3 numbers
5. Sort 3 numbers in ascending order
UNIVERSITY
OF
PERADENIYA
Add 2 numbers

Start

Declare variables
num1, num2, total

Read num1,
num2

total = num1 + num2

Print total

UNIVERSITY
OF
PERADENIYA
Stop
Calculate Grades
Start
True
65 > mark ≥ 50 grade = ‘C’
Declare variables
mark, grade False
True
50 > mark ≥ 40 grade = ‘D’
Read mark
False
True
mark ≥ 80 grade = ‘A’ grade = ‘F’

False
True
80 > mark ≥ 65 grade = ‘B’ Print grade

UNIVERSITY False
OF
PERADENIYA
Stop
Display numbers from 1 to 10
Start

Declare variables i

i=1

False
i ≤ 10 Stop

True

Print i

UNIVERSITY
OF
i=i+1
PERADENIYA
Pseudocode Keywords

• //: This keyword used to represent a comment.


• BEGIN, END: Begin is the first statement and end is the last statement.
• INPUT, GET, READ: The keyword is used to inputting data.
• COMPUTE, CALCULATE: used for calculation of the result of the given
expression.
• ADD, SUBTRACT, INITIALIZE: used for addition, subtraction and initialization.
• OUTPUT, PRINT, DISPLAY: It is used to display the output of the program.
• IF, ELSE, ENDIF: used to make decision.
• WHILE, ENDWHILE: used for iterative statements.
• FOR, ENDFOR: Another iterative incremented/decremented tested
UNIVERSITY automatically.
OF
PERADENIYA
Activity

Write psudocode for the following scenario


1. Add 2 numbers
2. Calculate grades
– A: mark > 80
– B: 80>mark>65
– C:65>mark>50
– D: 50>mark>40
– F: 40>mark
3. Display numbers from 1 to 10
4. Find the largest among 3 numbers
5. Sort 3 numbers in ascending order
UNIVERSITY
OF
PERADENIYA

You might also like