Question
This week, you will be writing a program to test for primality of any number N (that is, to test if N is a prime
This week, you will be writing a program to test for primality of any number N (that is, to test if N is a prime number). Start by writing an algorithm (a set of precise mathematical steps that can be written into a program) to test for primality. For full credit, run the program and use it to test for primality on several numbers. See what the largest number your program can handle is before you find it too slow to yield a result in a reasonable time (if it takes longer than 10 minutes to execute, you are done).
Use your imagination. Remember that if the number N is even, it cannot be a prime number. You can write your program to simply see whether it is a multiple of any numbers smaller than N. Also, you can design your program to store all prime numbers less than N that your program has found, then take advantage of the fact that a number only needs to be tested to see if it is a multiple of those prime numbers smaller than N/2. If it is not, then it must be a prime number itself. You also might consider that the fastest way to find out if N is a multiple of p is to divide N by p and see if the result is a whole number.
THIS SHOULD BE DONE IN C# or C++
Thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started