You are on page 1of 4

Lecture 10: Practice Examples

CS 101: Introduction to Computing

Practice Examples

Zawar Hussain

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi

Lecture 10: Practice Examples

CS 101: Introduction to Computing

Pseudo code
Pseudo code can be broken down into five components.
Variables: has a name, a data type, and a value
Assignment: set = 5; set = num + set;
Input/output: Output Write / display / print
Input Read / get / input

Selection:

if expression
statement
else
statement
endif

Repetition:
while expression
statement(s)
endwhile
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi

Lecture 10: Practice Examples

CS 101: Introduction to Computing

Examples using IF-Else


1. Input the dimensions of a rectangle and print its area.
2. Input the dimensions of a rectangle and print area and
perimeter
3. Input the length of the side of a square, and print its area.
Produce an error message if the length is negative.
(i.e.validation)
4. Input 3 numbers and print either an "all 3 equal" or a "not
all equal" message
5. Input 3 numbers, and print the biggest.

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi

Lecture 10: Practice Examples

CS 101: Introduction to Computing

Examples
6: Write pseudo code that performs the following: Ask a user
to enter a number. If the number is between 0 and 10,
write the word blue. If the number is between 10 and 20,
write the word red. if the number is between 20 and 30,
write the word green. If it is any other number, write that it
is not a correct color option.
7: Write pseudo code to print all multiples of 5 between 1
and 100 (including both 1 and 100).
8: Write pseudo code that will count all the even numbers up
to a user defined stopping point.
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi

You might also like