Problem: Write a pseudocode to read in two numbers and find the average of the numbers print the average
Solution: Here is a pseudocode that reads in two numbers and calculates their average.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | START # Get the first number PRINT "Enter the first number:" INPUT firstNumber # Get the second number PRINT "Enter the second number:" INPUT secondNumber # Calculate the average of the two numbers average = (firstNumber + secondNumber) / 2 # Print the average PRINT "The average of the two numbers is: " + average END |
Here is a breakdown of the pseudocode:
The code starts by printing a prompt asking the user to enter the first number.
The user inputs the first number and it is stored in a variable called firstNumber
.
The code then prints a prompt asking the user to enter the second number.
The user inputs the second number and it is stored in a variable called secondNumber
.
The code calculates the average of the two numbers by adding firstNumber
and secondNumber
and dividing the result by 2. The average is stored in a variable called average
.
The code prints the value of average
, which is the average of the two numbers.
The code ends.