Home > Back-end >  C language function of prime number judgment
C language function of prime number judgment

Time:09-23

Bosses, I want to know what is wrong, I I think I may be judging prime Numbers there are leaks in that place, but I can't find out

CodePudding user response:

Not equal to p, less than p

CodePudding user response:

The
reference 1/f, Simple, Soft reply:
can't equal to p,


You this problem I have changed, but the problem that wasn't in it, because I remove the equal sign or not

CodePudding user response:

The
reference 1/f, Simple, Soft reply:
can't equal to p,


On the right, should be can't such as p, but there are still problems

CodePudding user response:

Send the source file to me, I help you to change the qq 3405187170

CodePudding user response:

refer to 4th floor, Simple, Soft reply:
send source files to me, I help you to change the qq 3405187170

Need not trouble you for you tell me where there is a hole is my own feeling I just missed a certain situation

CodePudding user response:

If I==0) (p %
Reutrn 0;
Don't break, because break out of circulation, and will not return,

CodePudding user response:

refer to 6th floor truth is right or wrong response:
if I==0) (p %
Reutrn 0;
Don't break, because break out of circulation, and will not return,

Right if is equal to zero, we jump out of the loop is ok, because it is not a prime number

CodePudding user response:

refer to 7th floor qq_46521413 response:
Quote: refer to the sixth floor truth is right or wrong response:
if I==0) (p %
Reutrn 0;
Don't break, because break out of circulation, and will not return,

Right if is equal to zero, we jump out of the loop is ok, because it is not a prime ah
because you didn't return in modern compiler complains,
Old compilation will be return the value of an uncertain, so how do you know to is in outer, or not,

CodePudding user response:


for(i=2; i<=p; I++)
{
If I==0) (p %
{
break;
return 0;
}
The else
Return 1;
}

No matter how you are such a for loop can only perform a ah

CodePudding user response:

Prime Numbers are only divisible by 1 and itself, hypothesis is p=39, blocks, and for loop in the implementation of the if statement but if statements do not satisfy the implementation, and implement the else, your program said p is a prime number but not 39, so you should put the blocks in the else should be on the outside of the for loop.

CodePudding user response:

references to the tenth floor @ big fool @ reply:
prime Numbers can only be 1 and he divided exactly by itself, assuming that is p=39, the for loop in the implementation of the blocks, and the execution of the if statement but if statements do not satisfy, else, you said your program p is a prime number but not 39, so you should put the blocks in the else should be on the outside of the for loop.

I understand thank you

CodePudding user response:

references 9/f, the king of love flow response:
for (I=2; i<=p; I++)
{
If I==0) (p %
{
break;
return 0;
}
The else
Return 1;
}

No matter how you are such a for loop can only perform a ah

Learned to understand the thank you thank you

CodePudding user response:

refer to 6th floor truth is right or wrong response:
if I==0) (p %
Reutrn 0;
Don't break, because break out of circulation, and will not return,

Understand understand understand thank you thank you
  • Related