Heeeeeeeelp

Anyone knows how to create a program that tells whether the input is prime number or not. And also, the program will terminates if the user input a number that is not prime. I want to know this. Please help me.
The brute force option is to test against a modulus of all smaller numbers.


Modulus looks for a remainder when a number is divided.
10%3; //returns 1, 3 does not divide evenly into 10
10%2; // returns 0, so 2 does divide evenly into 10
If a number divides without a remainder then a modulus returns 0;

So if all smaller numbers return non-zero then the original number is prime. Make sure you stop the test at 1 since 1 divides into everything.

Start there, once you've got that written come back here and show us what you've got. We'll give you hints on optimizing from there.
Last edited on
Topic archived. No new replies allowed.