Question: An array of prime numbers 2 - 4 9 9 is stored in a file primeNumbers txt . This program can allow to request

An array of prime numbers 2-499 is stored in a file "primeNumbers txt". This program can allow to request a number from the user and find the closest prime number to the input number (either higher or lower) and print the lower one if the number is in the middle of two.
Your program should run interactively until the user quits. Try to minimize the program execution time by using the appropriate searching method for finding the prime number(s). You need to record and report the number of comparisons executed for finding the prime numbers.
Sample Output
Enter a number between 2 and 4991
This number is outside the accepted range.
Do you want to continue (yn)?
Enter a number between 2 and 499:223
The closest prime is:223
The number of comparisons is:
Do you want to continue (yn)?y
Enter a number between 2 and 499:354
The closest prime is 353
The number of comparisons is:?
Do you want to continue (yn)?
Enter a number between 2 and 499:495
The closest prime is:491
The number of comparisons is:?
Do you want to continue (yn)?
Goodbye!
 An array of prime numbers 2-499 is stored in a file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!