2015 Old Spec

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

Question 4

Create a folder/directory Question4 for your new program.

The algorithm, represented using pseudo-code in Figure 4, and the variable table, Table 3, describe a program that calculates and displays all of the prime numbers between 2 and 50, inclusive.

The MOD operator calculates the remainder resulting from an integer division eg 10 MOD 3 = 1.

If you are unsure how to use the MOD operator in the programming language you are using, there are examples of it being used in the Skeleton Program.

Figure 4

OUTPUT "The first few prime numbers are:"
FOR Count1 = 2 TO 50 DO
Count2 = 2
Prime = "Yes"
WHILE Count2 * Count2 <= Count1 DO
IF (Count1 MOD Count2 = 0) THEN
Prime = "No"
Count2 = Count2 + 1
IF Prime = "Yes" THEN

Table 3

Identifier Data Type Purpose
Count1 Integer Stores the number currently being checked for primeness
Count2 Integer Stores a number that is being checked to see if it is a factor of Count1
Prime String Indicates if the value stored in Count1 is a prime number or not

What you need to do

Write a program for the algorithm in Figure 4. Run the program and test that it works correctly. Save the program in your new Question4 folder/directory.

11 Marks

+ 1 Mark for testing screenshot

Additional Question

Describe the changes that would need to be made to the algorithm shown in Figure 4, so that instead of displaying the prime numbers between 2 and 50, inclusive, it displays all the prime numbers between 2 and a value input by the user, inclusive.

3 marks