I am looking forward to improve my algorithm to find the next primenumber to the right to a given number. What I have so far is this:
int NextPrime(int a)
{
int i, j, count, num;
for (i = a + 1; 1; i++)
{
for (j = 2, count = 0; j <= i; j++)
{
if (i%j == 0)
{
count++;
}
}
if (count == 1)
{
return i;
break;
}
}
}
Tho this algorithm is not that efficent when running often. Can someone give advices on how the algorithm could be speed up or improved.