Prime Number


#include 
#include 
#define MAX 1000000 // Max num of prime needed
// we guess initially all r prime, so all are false
bool prime[MAX];

void seive(void)
{
    int i,j,l;
    prime[1]=true;//1 is not prime;

    for(i=4;i<=MAX;i+=2) // You can omit this if you can handle even number
        prime[i]=true; //Even num are not prime except 2

    l=sqrt(MAX);

    for(i=3;i<=l;i+=2)
    {
        if(prime[i]==false) // if i is prime ,it's multiple's are not prime
        for(j=i*i;j<=MAX;j=j+i+i)
        {
            prime[j]=true; // j non prime
        }
    }

    // Print prime
    for(i=1;i<100;i++)
        if(prime[i]==false)
            printf("%ld\n",i);
}
int main()
{
    seive();
    return 0;
}