157k views
2 votes
7. (a) An algorithm has been written in pseudocode to Input 50 numbers. Positive numbers are stored

in the array PosNum[ ]. Negative numbers are stored in the array NegNum ).
Zeros are not included in the positive and negative counts.
Count 0
PosCount Count
NegCount + Count
REPEAT
INPUT Number
IF Number > 0
THEN
PosCount PosCount + 1
PosNum[PosCount] = Number
ELSE
NegCount = NegCount
NegNum[NegCount] = Number
ENDIF
Count Count + 1
UNTIL Count >= 50
OUTPUT "There are ", PosCount," positive numbers"
OUTPUT "There are ", NegCount," negative numbers"
(b) The algorithm needs to be changed so there is no limit to how many numbers can be input.
When the number 9999 is input, the algorithm stops more numbers being input and outputs
the results. The number 9999 is not to be stored nor counted as a positive number.
Explain how you would change the algorithm.​

1 Answer

0 votes

Answer:

The numbers do not have to be stored and the counter is also unnecessary, so take out all lines with PosNum[], NegNum[] and Count.

The repeat...until clause can be changed to:

REPEAT

...

UNTIL Number = 9999

and the IF Number>0 THEN must be changed to

IF Number > 0 AND Number != 9999 THEN

That should do the trick.

User Hirasawa Yui
by
4.8k points