8,求2~n的素数和
小于10的素数的和是2 + 3 + 5 + 7 = 17,
1 int test8(int num){ 2 int i,j,k; 3 long sum = 2; 4 int sqr ; 5 if(num<=2) 6 return 0; 7 for(i=3; i<num; i+=1){ 8 k=1; 9 sqr = (int)sqrt(i); 10 for(j=2; j<=sqr; j++){ 11 if(i%j==0){ 12 k = 0; 13 break; 14 } 15 } 16 if(k) 17 sum += i; 18 } 19 return sum; 20 }