Skip to content
MathsGenie logo
Open app

Course home

  1. IGCSE
  2. Computer Science Edexcel
  3. Question bank

Develop code

EasyMediumHard
123456789101112131415161718192021222324252627
Question 20

Write a program to implement the logic in the pseudocode below which checks if a number is a perfect square.

Open Q02b in the code editor.

Write the program.

You must use the structure given in Q02b to complete the program.

Do not add any further functionality.

Save your code as Q02bFINISHED with the correct file extension for your programming language.

1 FUNCTION isPerfectSquare(pNumber)
2 BEGIN FUNCTION
3     IF pNumber < 0 THEN
4         isSquare = False
5     ELSE
6         isSquare = False
7         FOR count FROM 0 TO pNumber DO
8             IF count * count = pNumber THEN
9                 isSquare = True
10            END IF
11        END FOR
12    END IF
13    RETURN isSquare
14 END FUNCTION
15
16 SEND "Enter a positive integer: " TO DISPLAY
17 RECEIVE number FROM (INTEGER) KEYBOARD
18 SET result TO isPerfectSquare(number)
19
20 IF result = True THEN
21     SEND (number & " is a perfect square") TO DISPLAY
22 ELSE
23     SEND (number & " is not a perfect square") TO DISPLAY
24 END IF
[11]

Develop code Questions

  1. IGCSE
  2. /Computer Science
  3. /Develop code