well Antony, well, Here we give aprogram which will find all primes between 100 to 100000. The program is given below-
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
typedef unsigned long long bignum;
void printPrime(bignum bn)
{
static char buf[100000];
sprintf(buf, "%ull", bn);
buf[strlen(buf) - 2] = '\0';
printf("%s\n", buf);
}
void findPrimes(bignum topCandidate)
{
bignum candidate = 100;
while(candidate <= topCandidate)
{
bignum trialDivisor = 2;
int prime = 1;
while(trialDivisor * trialDivisor <= candidate)
{
if(candidate % trialDivisor == 0)
{
prime = 0;
break;
}
trialDivi sor++;
}
if(prime) printPrime(candidate);
candid ate ++;
}
}
int main(int argc, char *argv[])
{
bignum topCandidate = 100000;
if(argc > 1)
topCandidate = atoll(argv[1]);
findPrimes(to pCan didate);
return 0;
}
Answered by
Romi
, an ibibo Master,
at
6:37 PM on June 20, 2008