|
|
вернуться в форумWhy Compilation error?-- Help me,Thank you. #include <cstdio> #include <cmath> #include <memory> const int MAX = 170001; bool prime[MAX]; int p[15001]; void findPrime() { int i,j; memset(prime,true,sizeof(prime)); //for(i = 0;i <MAX; i++) // prime[i] = true; for(i = 2;i < sqrt(MAX);) { if(prime[i] == true) for(j = i * i;j < MAX; j += i) prime[j] = false; if(i == 2) i++; else i += 2; } } int main() { findPrime(); int i,k,j; j = 1; for(i = 2;i < MAX; i++) { if(prime[i]) p[j++] = i; } scanf("%d",&k); while(k--) { scanf("%d",&i); printf("%d\n",p[i]); } return 0; } Re: Why Compilation error?-- Help me,Thank you. I got it. In the FAQ,it says that, In C/C++ you cannot call functions from header math.h with integer parameters. This code will not be compiled: sqrt(2). You can write correctly sqrt((double)2) or sqrt(2.0). |
|
|