function square(n)
return n * n
endfunctionsquare.[1]square(6) + 1.[1]Show the answer and mark scheme
- a function returns a value, but a procedure does not
- n
- 37
OCR GCSE Computer Science (J277) · Algorithms and programming (Paper 2) › Programming fundamentals › Additional programming techniques
Practise Functions and procedures. 11 exam-style questions plus unlimited generated ones on this subtopic, at up to four difficulty levels, with full mark schemes and a progress tracker. Free, no account needed.
Build a paper on this topic▶ Watch videos on Functions and procedures (Craig 'n' Dave OCR on YouTube) · Practise all of Additional programming techniques
Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.
function square(n)
return n * n
endfunction Identify the parameter used by the function square.procedure greet(name)
print("Welcome, " + name)
endprocedure
greet("Leah")
greet("Sam")Written for this site in the style of OCR exam questions. They are not taken from real past papers.
function square(n)
return n * n
endfunctionsquare.[1]square(6) + 1.[1]01 global total = 0
02 procedure addPoints(p)
03 bonus = 5
04 total = total + p + bonus
05 endprocedure
06 addPoints(10)
07 addPoints(3)
08 print(total)isPrime that takes a whole number as a parameter and returns True if it is prime and False if it is not.isPrime to output every prime number from 1 to 50.[2]isPrime is written as a function rather than as a procedure.[1]function isPrime(n)
if n < 2 then
return false
endif
for d = 2 to n - 1
if n MOD d == 0 then
return false
endif
next d
return true
endfunctionfor i = 1 to 50
if isPrime(i) then
print(i)
endif
next iStuck? Get 1-to-1 help. Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.
Book a free trial