您现在的写法,在找到第n个质数后会在找到的数上再加一,因为c++是在出for循环前要执行的。改成下面的就好了:for(c=0; count<=n; ){c++;while(isPrime(c)){ count++;break; }}