题目
#include <stdio.h>
#include <math.h>
int panduan(int m);
int isprime(int x);
int main()
{
int n;
printf("Input n:");
scanf("%d",&n);
printf("%d\n",isprime(n));
}
int panduan(int m)
{
int i;
if(m==1||m == 2)
return 0;
for(i=2; i<m; i++)
{
if(m%i==0) return 0;
}
return 1;
}
int isprime (int x)
{
while (1) {
x++;
if(panduan(x) == 1)
break;
}
return x;
}
Input n:257
263
Program ended with exit code: 0
区别:注意x++所在的位置
#include <stdio.h>
#include <math.h>
int panduan(int m);
int isprime(int x);
int main()
{
int n;
printf("Input n:");
scanf("%d",&n);
printf("%d\n",isprime(n));
}
int panduan(int m)
{
int i;
if(m==1||m == 2)
return 0;
for(i=2; i<m; i++)
{
if(m%i==0) return 0;
}
return 1;
}
int isprime (int x)
{
while (1) {
if(panduan(x++) == 1)
break;
}
return x;
}
Input n:257
258
Program ended with exit code: 0