Home > Back-end >  Application of simple function use to judge whether it is prime, run out and can't correct judg
Application of simple function use to judge whether it is prime, run out and can't correct judg

Time:09-23

#include
Int isPrime (int n)
{
int i=0;
If (n
=2){
return 0;
}
for(i=2; i<=n - 1; I++)
{
If I (n %==0)
{
break;
}
}
If (I==0)
{
return 0;
}
return 1;
}
Int main ()
{
int k;
Printf (" input a number \ n ");
The scanf (" % d ", & amp; K);
If (isPrime (k)==0)
{
Printf (" is a prime number ");
}
The else
{
Printf (" is not a prime number ");
}
return 0;
}

CodePudding user response:

Break there directly returns 0, said it had not a prime number

CodePudding user response:

Bool is_prime (int number)
{
If (number & lt;
=2)return true;
for(int i=2; i{
If (number % I==0)
return false;
}
return true;
}

CodePudding user response:

reference 1/f, Simple, Soft reply:
break there directly returns 0, said is not the prime

Bosses that directly in my how should change on the part function without changing the

CodePudding user response:

Don't have to break the back of the code, direct return 1, break it returns 0

CodePudding user response:

refer to 4th floor, Simple, Soft reply:
don't have to break the back of the code, direct return 1, break there returns 0

Well well well good

CodePudding user response:

refer to 4th floor, Simple, Soft reply:
don't have to break the back of the code, direct return 1, break there returns 0

Thank you very much??????
  • Related