Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

22
Dec

Find out a number is prime number or not?

Related Blog Items

Here is a code snippet which find out whether a number is prime or not,
Please post if you have a better solution….

Solution:

/* returns true if number is prime
 else 0 */
int prime(int n)
{
    int i;
 
    if (!(n % 2)) 
    {
      return (n == 2);
    }
 
    for(i = 3; i < n; i ++)
    {
        if (!(n % i))
            return 0;
    }
 
    return 1;
}

Popularity: 9%

You need to log on to convert this article into PDF


Related Blog Items

1 Comment

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image