Example Algorithms
Example 1: Input a grade between 0 and 100. If the grade is greater than 50 display
pass, otherwise display fail.
1. Declare Variable to input a grade – grade
2. If grade >=50
a. Print to Screen “Pass”
3. Else if grade is less than 50
a. Print Fail
This could also be written without numbering and just indentation as follows:
Declare Variable to input a grade – grade
If grade >=50
Print to Screen “Pass”
Else if grade is less than 50
Print Fail
Example 2: Write a program to count all of the negative numbers entered by a user.
Enter -1 to exit.
1. Initialise variables
a. The number to read in, number
b. The counter variable, count
2. While the number is not equal to -1
a. Ask the user to enter a number
b. Increment the counter, count
3. When the number is equal to -1
a. Print the counter variable out to screen.
Example 3: Find the maximum number of a number of numbers read in.
1. Initialise variables
a. Define max to be a very low number or to the first number entered.
2. While the sentinel value is not reached
a. Keep reading in a number
b. If the number is greater than max
i. Set the max equal to the number