Prime Number function

Hi.I am new to this forum.I am developing a program which has a function that tells whether the value passed to it is prime or not.can anyone guide me with this?
EDIT:Does this code work??
1
2
3
4
5
6
7
8
9
int IsPrime(int number)
{
    for (int i = 2; i < number; i++)
    {
      if (number % i == 0 && i != number)
        return false;
    }
    return true;
}


Thanks
Last edited on
Hi hacker804,

Do you have any code?
Put the code and hit the "Submit" button, dude!
There some formula(method) to check whether a no is prime or not.I don't remember it but it was in my book.(applied till 100 only)

Other thing you can do is test no with primes before it.(and less then half)
1)check no is one or not - One is neither a prime nor a composite number
2)else check its 2 or not - 2 is prime
3)else check its even or odd - even are not prime
4)if odd then find its half.Check it with prime number before its half.
(this is long method I know but...)
Topic archived. No new replies allowed.