Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

count number of prime numbers in a given range in c

#include <iostream>
using namespace std;
int main()
{
    int n1=0,n2=100,count=0;
    for(int i=n1;i<=n2;i++)
    {
        int c=0;
        for(int j=1;j<=i;j++)
        {
            if(i%j==0)
            {
                c++;
            }
        }
        if(c==2)
        {
            count++;
        }
    }
    cout<<count;
    return 0;
}
 
PREVIOUS NEXT
Tagged: #count #number #prime #numbers #range
ADD COMMENT
Topic
Name
7+6 =