Asked by robert
Design the logic for a program that allows a user to enter any amount of numbers up to 10 or until a sentinal
value of -1 is entered.
Then the program displays the count of the numbers entered and numeric average of
the numbers (not including the -1 of course).
After display the average of all the entered numbers, the
program will then display each number and its difference from that average.
value of -1 is entered.
Then the program displays the count of the numbers entered and numeric average of
the numbers (not including the -1 of course).
After display the average of all the entered numbers, the
program will then display each number and its difference from that average.
Answers
Answered by
Steve
x=0
i=0
sum=0
while x ≠ -1
read x
if x ≠ -1 { v[++i] = x; sum+=x }
end while
print i
if i==0 exit
avg = sum/i
print avg
for j=1..i print v[j],v[j]-i
you can add any labels you see fit for user interaction.
i=0
sum=0
while x ≠ -1
read x
if x ≠ -1 { v[++i] = x; sum+=x }
end while
print i
if i==0 exit
avg = sum/i
print avg
for j=1..i print v[j],v[j]-i
you can add any labels you see fit for user interaction.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.