top of page
PROGRAMMING CHALLENGES
Prime Number Generator
Difficulty:
3 Hard
1.7 Iteration (for loops)
Topic:
Write a program that generates and displays all prime numbers within a specified range. A prime number is a natural number greater than 1 that is only divisible by 1 and itself.
INPUTS: Start and end of the range (integers)
PROCESSES:
1. Accept user input for the start and end of the range
2. Use a nested for loop to iterate through the range
3. Inside the inner loop, check if the current number is divisible by any number between 2 and the square root of the current number
4. If no divisor is found, print the current number as a prime number
OUTPUTS: List of prime numbers within the specified range (integers)
PROCESSES:
1. Accept user input for the start and end of the range
2. Use a nested for loop to iterate through the range
3. Inside the inner loop, check if the current number is divisible by any number between 2 and the square root of the current number
4. If no divisor is found, print the current number as a prime number
OUTPUTS: List of prime numbers within the specified range (integers)
Need help with your programming skills?
If you need more help than just independent practise, then we're here for you. Book a 1:1 with us and we will be able to guide you to becoming a proficient programmer who can tackle any of the challenges an exam board can throw at you.
1 hr
40 British pounds1 hr
50 British pounds
bottom of page