Difference between revisions of "2015 Old Spec"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Figure 4)
(Figure 4)
 
(2 intermediate revisions by the same user not shown)
Line 11: Line 11:
 
==Figure 4==
 
==Figure 4==
  
<nowiki>
+
 
OUTPUT "The first few prime numbers are:"<br/>
+
:OUTPUT "The first few prime numbers are:"
FOR Count1 = 2 TO 50 DO
+
:FOR Count1 = 2 TO 50 DO
  Count2 = 2
+
::  Count2 = 2
  Prime = "Yes"
+
::  Prime = "Yes"
  WHILE Count2 * Count2 <= Count1 DO
+
::  WHILE Count2 * Count2 <= Count1 DO
    IF (Count1 MOD Count2 = 0) THEN
+
:::    IF (Count1 MOD Count2 = 0) THEN
      Prime = "No"
+
::::      Prime = "No"
    ENDIF
+
:::    ENDIF
    Count2 = Count2 + 1
+
:::    Count2 = Count2 + 1
  ENDWHILE
+
::  ENDWHILE
  IF Prime = "Yes" THEN
+
::  IF Prime = "Yes" THEN
    OUTPUT Count1
+
:::    OUTPUT Count1
  ENDIF
+
::  ENDIF
ENDFOR
+
:ENDFOR
</nowiki>
 
  
 
==Table 3==
 
==Table 3==

Latest revision as of 23:02, 28 November 2016

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"
ENDIF
Count2 = Count2 + 1
ENDWHILE
IF Prime = "Yes" THEN
OUTPUT Count1
ENDIF
ENDFOR

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