1 #include <stdio.h> 2 3 bool If_prime(int a,int b) 4 { 5 int c; 6 while(b>0) 7 { 8 c = a%b; 9 a = b; 10 b = c; 11 } 12 if(a==1)return true; 13 else return false; 14 } 15 int main() 16 { 17 int num,i; 18 while(true) 19 { 20 printf("input the 32-bit int number you want to check:\n"); 21 scanf("%d",&num); 22 for(i=2;i*i <= num;i++) 23 if(!If_prime(num,i))break; 24 if(i*i>num)printf("It`s a prime number.\n"); 25 else printf("It`s not a prime number.\n"); 26 } 27 28 return 0; 29 }
本文转自NewPanderKing51CTO博客,原文链接:http://www.cnblogs.com/newpanderking/archive/2012/04/25/2470261.html ,如需转载请自行联系原作者