int()是你定义的函数么?如果是类型转化要用tmp=(int)(sqrt(x));其次,i要先声明在使用 最后,这个函数如果是判断素数的话,逻辑上也有错误……我就顺便改了吧:int isprime(int x){ int tmp;if (x==2) return 1;if (x==0) return 0;else { int i;for (i=2;i*i<=x;i++){ ...
isPrime变量的作用域是在for循环里,出了for循环就不存在isPrime这个变量的,所以提示没定义。
This MATLAB function returns a logical array containing 1 (true) where the elements of the array X are prime numbers, and 0 (false) where they are not.
To check if the provided number is prime, the “sympy.isprime()” method, the “while” loop, and the user-defined function are used. The “sympy.isprime()” is the built-in method of the “sympy” library. This article described about multiple techniques to check whether the number is ...
>In a straight 'C' program ( for (x=1, x=(nbr+1), x++) etc... ) the x is initialized and forceably incremented. seems Python does not auto initialize but does auto increment. I think a better explanation is that in your original function, x only existed while the for loop was...
using namespace std; bool isprime(int a){ if(!a||a==1) return 0; for(int i=2;i<=sqrt(a);i++) if(!(a%i)) return 0; return 1;} int main(){ int n; cin>>n; for(int i=1,m;i<=n&&cin>>m;i++) if(isprime(m)) cout<<m<<...