Question 17

AQA Computer Science Specimen Paper 1A (8525/1A)GCSE3 marks

On the specification

17.1
3.2 Programming
17.2
3.2 Programming
17.3
3.2 Programming
Question text

17 Figure 8 shows a C# program that is being developed. It is supposed to calculate and display the highest common factor of two numbers entered by the user. The highest common factor of two numbers is the largest number that both numbers can be divided by without leaving a remainder. Examples: • the highest common factor of the numbers 6 and 9 is 3 • the highest common factor of 2 and 5 is 1 Line numbers are shown but are not part of the program code. Figure 8 1 int num1 = Convert.ToInt32(Console.ReadLine()); 2 int num2 = Convert.ToInt32(Console.ReadLine()); 3 int hcf = 1; 4 int count = 1; 5 while (count < num1) 6 { 7 if (num1 % count == 0 && num2 % count == 0) 8 { 9 hcf = count; 10 } 11 count = count + 1; 12 } 13 Console.WriteLine(hcf); The highest common factor of two numbers is the largest number that both numbers can be divided by without leaving a remainder. Examples: • the highest common factor of the numbers 6 and 9 is 3 • the highest common factor of 2 and 5 is 1 The program in Figure 8 works correctly sometimes but not always. When the user enters the numbers 4 and 6 it correctly outputs 2, but when the user enters the numbers 4 and 4 it should output 4 but it does not. 17.1 State the output from the program in Figure 8 when the user enters the numbers 4 and 4 [1 mark] 17.2 State the line number from the program in Figure 8 which contains the error that stops the program from sometimes working correctly. [1 mark] 17.3 Describe how the line of code identified in your answer to 17.2 should be changed so that the program in Figure 8 will work correctly. [1 mark]