Question 6

OCR Computer Science June 2023 Algorithms and programming (H446-02)A level6 marks

On the specification

1.4 Data types, data structures and algorithms2.2 Problem solving and programming
Question text

6 Octal is a base 8 number system. To convert a denary number to base 8: • the denary value is divided by 8 and the remainder is stored • the integer value after division is divided by 8 repeatedly until 0 is reached • the remainders are then displayed in reverse order. Example 1: Denary 38 38 / 8 = 4 remainder 6 6 4 / 8 = 0 remainder 4 4 Octal = 46 Example 2: Denary 57 57 / 8 = 7 remainder 1 1 7 / 8 = 0 remainder 7 7 Octal = 71 Write an algorithm to: • take a denary value as input from the user • convert the number to octal • output the octal value. You do not need to validate the input from the user. Write your algorithm using pseudocode or program code. [6]