1 #include <stdio.h> 2 #include <math.h> 3 4 int main(int argc, char* argv[]) 5 { 6 int m,i,k; 7 printf("please input the integer number:\n"); 8 scanf("%d",&m); 9 k=(int)sqrt(m); 10 for (i=2;i<=k;i++) 11 { 12 if (m%i==0) 13 { 14 break; 15 } 16 } 17 if (i>k) 18 { 19 printf("%d is a prime number \n",m); 20 } 21 else 22 { 23 printf("%d is not a prime number \n",m); 24 } 25 return 0; 26 }
注意i++到后面可能会变成
i=k+1