You are on page 1of 1

bool isPrime(int n)

int count;
count =0;
for (int i=1;i<=n;i++)
{
if(n % i==0)
{
count++;
}
}
if (count == 2)
return true;
else
return false;
return 0;

this is what you did, keeping count of the numbers which perfectly divide the g
iven number is unnecessary.
so what we will do is only check if the given number is divisible by any number
greater than 2 if yes then it is not prime, so return false....if no then it is
a prime no. return true

You might also like