1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| # include <stdio.h> # include <math.h> int judge(int a); int main (void) { int a,b,c=0; for (a=101;a<=200;a++) { b = judge(a); if (b == 1) { c += 1; } } printf("101-200 have prime number:%d\n",c); return 0; }
int judge (int a) { int b,c,i; b = sqrt(a); for (i=2;i<=b;i++) { if (a%i==0) { break; } } if (i>b) { c = 1; } else { c = 0; } return c; }
|