Posted by
கேசவன் முத்துவேல்
"An integer is prime if its only positive divisors are itself and one. Prime numbers have always been a keen interest to mathematicians for various reasons. One being there appears to be no rhyme or reason to the distribution of primes and there is no limit to finding new primes. The largest known prime was found in November 2001 and it is over 4 million digits long! (see other links below) Finding Primes Computers have made finding these large prime numbers possible. The faster computers can crunch numbers, the larger the primes will be found. Here's an interesting graph showing the largest known primes by year. Simple Method of Finding Primes A prime number is one that has no prime factors. So a simple way of checking if a number is prime is by trying all known primes less than it and seeing if it divides evenly into that number. Example: Finding the first couple of primes Starting off with the number 2, it is prime because the only divisors are itself and 1, meaning the only way to multiple two numbers to get 2 is 2 x 1. Likewise for 3. So that starts us off with two known primes 2 and 3. To check the next number we can check if 4 modulo 2 equals 0. This means when divide 2 into 4 there is no remainder, which means 2 is a factor of 4. Specifically we know 2 x 2 = 4. Thus 4 is not prime. Moving on to the next number: 5. To check"
ANY ONE RUN THIS C Program.., & Enjoy the primes..,
/*
Prime Number Finder
Marcus Kazmierczak, marcus@mkaz.com
Created On: March 18, 2002
# findthem.c $Revision: 1.3 $
# Last Updated: $Date: 2002/03/19 06:59:11 $
*/
#include
#include
/*== start/stop range ==*/
#define START 5 // MUST BE ODD
#define STOP 99999999
int main(void)
{
int nap;
long num, c, i;
long *prime;
prime = malloc((STOP/3) * sizeof(long));
if (!prime) { printf("Memory Allocation Error."); exit(1); }
prime[0] = 2; prime[1] = 3;
c = 2; /*== initial primes ==*/
/*== only have to check odd numbers ==*/
for (num=START; num < STOP; num = num + 2)
{
nap = 0; // set not-a-prime false
/*= cycle through list of known primes =*/
for (i=0; i < c; i++)
{
/*= check if a previous prime divides evenly =*/
/*= if so the number is not a prime =*/
if ((num % prime[i]) == 0) { nap = 1; break; }
/*= stop if prime squared is bigger than the number =*/
if ((prime[i] * prime[i]) > num) { break; }
}
/*= if not-a-prime, then we found a prime =*/
if (nap != 1)
{
/*= add prime to list of known primes =*/
prime[c] = num; c++;
printf("%d \n",num);
}
}
free(prime);
}
Thanks : mkaz.com: