Recently I need to add some of this kind of functionality in my on-going project and for that, I wrote some simple method to returning the count of prime Numbers contain for given input number…. so I just want to have this snippet in front of you… Hope it will help as.. as it is simple but while implementing it kills our brain surely 🙂

static int getNumberOfPrimes(int N) {
     
    int count = 0;
    bool res = false;
    for(int i=2;i<=N;i++)
    {
        res = false;
        for(int j=2;j<=i;j++)
        {
            if(i%j == 0 && i!=j)
            {
                res = true;
            }
        }
        if(!res)
            count++;
    }
     
    return count;
 
}

Hope it will help you 🙂