1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int isPrime(int n); 5 6 int main() 7 { 8 int cnt = 0; 9 int i; 10 for(i = 101; i <= 200; i++) 11 if(isPrime(i)) 12 { 13 ++cnt; 14 printf("%5d",i); 15 } 16 printf("\n\nThe number of prime is %d\n",cnt); 17 system("pause"); 18 return 0; 19 } 20 21 int isPrime(int n) 22 { 23 int i; 24 if(n < 2) 25 return 0; 26 else if(n == 2) 27 return 1; 28 if(n % 2 == 0) 29 return 0; 30 for(i = 3; i * i <= n; i += 2)//i <= sqrt(n) 31 if(n % i == 0) 32 return 0; 33 return 1; 34 }
时间: 2024-11-05 12:25:35