Pseudocode CS Thinking Example 3
Follow the full solution, then compare it with the other examples linked below.
Example 3
mediumWrite pseudocode for a program that reads a list of 10 numbers and outputs how many are above average.
Solution
- 1 Step 1: Read 10 numbers into an array. Calculate the sum and divide by 10 to find the average.
- 2 Step 2: Loop through the array, count how many values are greater than the average, and output the count.
Answer
FOR i = 0 TO 9: numbers[i] = INPUT(). average = SUM(numbers) / 10. SET count = 0. FOR i = 0 TO 9: IF numbers[i] > average THEN count = count + 1. OUTPUT count.
This problem requires two passes through the data โ first to calculate the average, then to count values above it. Pseudocode makes this two-pass logic clear before coding.
About Pseudocode
An informal, human-readable description of an algorithm using structured language that resembles code but is not tied to any specific programming language. Pseudocode uses plain English mixed with programming constructs like IF, WHILE, and FOR to describe logic without worrying about syntax rules.
Learn more about Pseudocode โMore Pseudocode Examples
Example 1 easy
Write pseudocode for a program that asks the user for two numbers and outputs the larger one.
Example 2 mediumConvert the following Python code to pseudocode: total = 0; for i in range(1, 11): if i % 2 == 0: to
Example 4 hardA colleague writes pseudocode that mixes Python syntax, uses unclear variable names, and skips steps