Skip to content

Course home

Develop code

Develop code

EasyMediumHard
1234567891011121314151617181920212223242526
Question 19

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]
Markscheme

Develop code Questions

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

62 exam-style questions on Edexcel IGCSE Computer Science Develop code. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank