Skip to content

Course home

Structured programming and subroutines (procedures and functions)

Structured programming and subroutines (procedures and functions)

EasyMediumHard
12345678910111213141516
Question 4

Write a subroutine NINES_COMPLEMENT, using either pseudo-code or a flowchart, that takes a single numeric digit character as a parameter and returns its "nine's complement" character (the digit character that, when added to the input digit, sums to 9).

For example, if the subroutine is passed the character '3', it should return the character '6' (since 3+6=93 + 6 = 93+6=9). If it is passed the character '0', it should return the character '9'.

You must make use of the built-in subroutines INT_TO_CHAR and CHAR_TO_INT in your answer:

  • CHAR_TO_INT(character) returns the integer ASCII/Unicode code for a character (e.g., CHAR_TO_INT('0') returns 48, and CHAR_TO_INT('9') returns 57).
  • INT_TO_CHAR(integer) returns the character corresponding to that ASCII/Unicode code (e.g., INT_TO_CHAR(50) returns '2').

You can assume that the parameter passed to the subroutine will always be a valid digit character between '0' and '9'.

[5]
Markscheme

Structured programming and subroutines (procedures and functions) Questions

  1. GCSE
  2. /Computer Science
  3. /Structured programming and subroutines (procedures and functions)

131 exam-style questions on AQA GCSE Computer Science Structured programming and subroutines (procedures and functions). Each one has a worked solution and a mark scheme showing where the marks go.

Question bank