Your problem is the break
statement, remove it.
int next(int x)
{
int y, i;
for(i=x+1; i>0; i++)
{
if(is_prime(i)==1)
return i;
break; //delete this line
}
}
What is happening is that, after every first test, you are immediately breaking out of the loop. Which is why numbers like 6, 10, and 12 are working. That is because the next number immediately after is a prime number. For every other case where the next immediate number is not prime, this won't work; it will break if a prime isn't reached. If you want to execute more than one statement in an if-branch, you must wrap them in {}
braces.
This is the correct form for multiple statements in an if-branch:
if(is_prime(i)==1)
{
return i;
break;
}