Find smallest prime number greater than given n
You can implement function isPrime to test primality in a little more efficient manner:

int isPrime(int n) // assuming n &gt; 1
{
    int i,root;

    if (n%2 == 0 || n%3 == 0)
        return 0;

    root = (int)sqrt(n);

    for (i=5; i&lt;=root; i+=6)
    {
        if (n%i == 0)
           return 0;
    }

    for (i=7; i&lt;=root; i+=6)
    {
        if (n%i == 0)
           return 0;
    }

    return 1;
}