2018 A Level

From TRCCompSci - AQA Computer Science
Revision as of 13:59, 4 December 2018 by Admin (talk | contribs) (Question 5)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Question 5

Write a program that checks which numbers from a series of numbers entered by the user are prime numbers.

The program should get a number from the user and then display the messages:

  • "Not greater than 1" if the number entered is 1 or less
  • "Is prime" if the number entered is a prime number
  • "Is not prime" otherwise.

The user should then be asked if they want to enter another number and the program should repeat if they say that they do.

A prime number is a positive integer that will leave a remainder if it is divided by any positive integer other than 1 and itself. You may assume that each number entered by the user is an integer.

If your program only works correctly for some prime numbers you will get some marks for this question. To get full marks for this question, your program must work correctly for any valid integer value that the user enters.

Task 1

Code the above

Task 2

showing the result of testing the program by:

  • entering the number 1
  • then choosing to enter another number
  • then entering the number 5
  • then choosing to enter another number
  • then entering the number 8
  • and then choosing not to enter another number.