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