• We need your support!

    We are currently struggling to cover the operational costs of Xtremepapers, as a result we might have to shut this website down. Please donate if we have helped you and help make a difference in other students' lives!
    Click here to Donate Now (View Announcement)

AS Computing Psuedocode

Messages
373
Reaction score
125
Points
53
Hey guys, I am having problems with pseudocodes. Can anyone explain this psuecode for me and its question:
n<---0
WHILE n<=0
INPUT n
ENDWHILE

Total<--0
Count<--0

REPEAT
INPUT Number
Total <--Total + Number
Count<-- Count+1
UNTIL Count=n

OUTPUT Total/Count

Question:
Trace the psuedocode algorithm for the following sequence of data input:0,-5,5,2,5,4,6,3

Answer:
FInal output is 4
 
Messages
878
Reaction score
1,474
Points
153
make a trace table and dry run it or you can just do it in your head

at the beginning, 'n' is assigned the value 0. This makes the condition for the loop true since n=0 and so we run the loop...
INPUT n <======= inject the first value from the data input sequence which is 0
0 satisfies the condition so the loop will be executed again.
Now put another value as input from the given input set and that is -5
-5<0 so the loop is executed again
next value is 5 and the condition is not met now
at this moment, n = 5. Remember this or write it down
total = 0
count = 0
next comes repeat until loop
INPUT Number <======= We have already used 0,-5,5 so we input the next data whch is 2
just keep entering the values from the provided data set and follow through and eventually you will end up with 20/5 = 4
 
Messages
373
Reaction score
125
Points
53
make a trace table and dry run it or you can just do it in your head

at the beginning, 'n' is assigned the value 0. This makes the condition for the loop true since n=0 and so we run the loop...
INPUT n <======= inject the first value from the data input sequence which is 0
0 satisfies the condition so the loop will be executed again.
Now put another value as input from the given input set and that is -5
-5<0 so the loop is executed again
next value is 5 and the condition is not met now
at this moment, n = 5. Remember this or write it down
total = 0
count = 0
next comes repeat until loop
INPUT Number <======= We have already used 0,-5,5 so we input the next data whch is 2
just keep entering the values from the provided data set and follow through and eventually you will end up with 20/5 = 4
Thanks
 
Top