+ (plus)
- (minus)
* (multiplication)
/ (division)
^ (raised to the power of)
MOD (remainder)
Syntax:
MOD(<identifier1>, <identifier2>)
Returns the remainder of identifier1 divided by identifier2.
The identifiers are of data type integer.
Example
MOD(15, 4) returns 3
DIV
Syntax:
DIV(<identifier1>, <identifier2>)
Returns the quotient of identifier1 divided by identifier2 with the fractional part discarded.
Example
DIV(17,2) returns 8
ROUND
Syntax:
ROUND(<identifier>, <n>)
Returns the value of the identifier rounded to n number of decimal places.
The identifier should be of data type real, n should be of data type integer.
Example
ROUND(45.63, 1) returns 45.6
ROUND(23.698, 2) returns 23.67
RANDOM
Returns a random number between 0 and 1 inclusive.
Syntax:
RANDOM()
Example
Write an algorithm that outputs 5 random files.
Solution:
FOR count ← 1 TO 5
OUTPUT RANDOM()
NEXT count
Write an algorithm that outputs random numbers between 0 and 20.
Solution:
FOR count ← 1 TO 5
number ← RANDOM()*20
OUTPUT number
NEXT count
= (equal)
< (smaller than)
<= (smaller than or equal to)
> (bigger than)
>= (bigger than or equal to)
<> (not equal to / different)
Task 1
Add comments to each line to predict what it will do. Comments start with //
OUTPUT 8 + 2
OUTPUT 8 - 2
OUTPUT 8 * 2
OUTPUT 8 / 2
Task 2
Write pseudocode to ask for two numbers and output the addition of both numbers
Task 3
What is the output of the following algorithm? ...............................
num1 <- 20
num2 <- 5
result <- num1 * num2
OUTPUT result
Task 4 - Maths with input
Predict what the following code will do.
INPUT num1
num2 <- 10
result <- num1 * num2
OUTPUT result
Task 5 - Area Calc
Create a program that allows the user to enter 2 numbers representing the width and length of a rectangle. The program calculates and displays the area of the rectangle.
Task 6 - Challenges
PerimeterCalc
Create a program that allows the user to enter 2 numbers representing the width and length of a rectangle. The program calculates and displays the perimeter of the rectangle.
Restaurant Tip Calculator
Write an algorithm that allows the user to enter the price of a meal at a restaurant. The program calculates the amount of the tip to be paid at 20%. The tip and total price are then displayed separately.
Volume and Surface Calc
Write an algorithm that allows the user to enter 3 numbers representing the height, width and length of a cuboid. The program calculates and displays the volume and total surface area of the cuboid.
Task 7 - Conversion
Write an algorithm that allows you to:
enter degrees in Celsius
converts the Celsius degrees to Fahrenheit
outputs the degrees in Fahrenheit
Task 8
Write an algorithm that allows you to:
enter a distance in kilometres
converts the kilometres to meters
outputs the distance in meters