Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
936 views2 pages

Pseudo Code Exercise-1 Solution

The document provides pseudo code to: 1) Read in 5 numbers, calculate the average, and find the minimum and maximum values. 2) Write out the results with descriptive messages. 3) Calculate a running sum by adding entered numbers until a negative number is encountered, then output the final sum.

Uploaded by

carlynn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
936 views2 pages

Pseudo Code Exercise-1 Solution

The document provides pseudo code to: 1) Read in 5 numbers, calculate the average, and find the minimum and maximum values. 2) Write out the results with descriptive messages. 3) Calculate a running sum by adding entered numbers until a negative number is encountered, then output the final sum.

Uploaded by

carlynn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Pseudo Code Exercise-1

Write pseudo code that will perform the following:


1) Read in 5 separate numbers.
2) Calculate the average of the five numbers.
3) Find the smallest (minimum) and largest (maximum) of the five entered numbers.
4) Write out the results found from steps b and c with a message describing what they are
5) Write pseudo code that will calculate a running sum. A user will enter numbers that will be
added to the sum and when a negative number is encountered, stop adding numbers and
write out the final result.

Solution:
Pseudo code
a) Write "please enter 5 numbers"
Read n1, n2, n3, n4, n5
b) Write "The average is"
Set avg to (n1+n2+n3+n4+n5)/5
Write avg
c) If (n1 < n2)
Set max to n2
Else
Set max to n1
If (n3 > max)
Set max to n3
If (n4 > max)

Set max to n4
If (n5 > max)
Set max to n5
Write "The max is"
Write max

1
d) If (n1 > n2)
Set min to n2
Else
Set min to n1
If (n3 < min)
Set min to n3
If (n4 < min)
Set min to n4
If (n5 < min)
Set min to n5
Write "The min is"
Write min

e) Read x
Set sum to 0;
While (x >= 0)
Set sum to x + sum
Read x

You might also like