0% found this document useful (0 votes)
23 views5 pages

CS Paper 2 Answers

Uploaded by

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

CS Paper 2 Answers

Uploaded by

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

Paper 22- May/June 2021 (Section B Answers)

Write an algorithm in pseudocode to input 500 positive whole


numbers.
Each number input must be less than 1000.
Find and output the largest number input, the smallest number
input and the range (difference between the largest number and
smallest number).
Highest <- 0
Smallest <- 1000
FOR Count <- 1 TO 500
REPEAT
OUTPUT ‘Enter a whole number between 1 and 999’
INPUT Num
UNTIL Num >= 1 AND Num < 1000 AND Num = Num DIV 1 //Makes
sure Number is positive
IF Num > Highest:
THEN
Highest <- Num
ENDIF
IF Num < Smallest:
THEN
Smallest <- Num
ENDIF
NEXT
Range <- Highest - Smallest
OUTPUT ‘The highest number input is’, Highest
OUTPUT ‘The smallest number input is’, Smallest
OUTPUT ‘Range of numbers’, Range
Pseudocode Statement Flowchart Symbol

IF Number = 20

IF Number =
20

PRINT Number

PRINT Number

Number <- Number + 1

Number <- Number + 1

(b) State the type of each pseudocode statement. For example, X ← X + Y is totalling.

IF Number = 20 Ans: Condition

PRINT Number Ans: Output

Number ← Number + 1 Ans: Incrementing

[3]
(b) Explain how the algorithm could be extended to allow three attempts at inputting the matching
password. Any pseudocode statements used in your answer must be fully explained.

Ans: Use a counter that will allow the conditions in the code to go for 3 times and then stop.

5. A one-dimensional array dataArray [1:20] needs each element set to zero.

(a) Write a pseudocode routine that sets each element to zero. Use the most suitable loop
structure.

(b) Explain why you chose this loop structure.

You might also like