Home > Back-end >  Request is palindrome is a prime number, why is not the same as the two code to run out.
Request is palindrome is a prime number, why is not the same as the two code to run out.

Time:05-04

#include
#include
Int sushu b (int);
C int huiwen (int);
Int main ()
{int a;
For (a=100; a<1000; +)
{if (sushu (a) & amp; & Huiwen (a))
Printf (" % d \ n ", a);
}
return 0;
}
Int sushu (int b)
{int e, f;
E=SQRT (b);
For (f=2; F<=e; F++)
If (b % f==0)
return 0;
}
Int huiwen (int) c
{int g, h;
G=c/100;
H=c % 10;
If (g==h)
return 1;
return 0;

}





#include
#include
Int sushu b (int);
C int huiwen (int);
Int main ()
{int a;
For (a=100; a<1000; +)
{if (sushu (a) & amp; & Huiwen (a))
Printf (" % d \ n ", a);
}
return 0;
}
Int sushu (int b)
{int e, f;
E=SQRT (b);
For (f=2; F<=e; F++)
If (b % f!=0)
return 1;
}
Int huiwen (int) c
{int g, h;
G=c/100;
H=c % 10;
If (g==h)
return 1;
return 0;

}

CodePudding user response:

Both wrong ah, verify prime function must to return 0 and return 1? So just logical,

CodePudding user response:

Modify the first, for reference:
 # include 
#include
Int sushu b (int);
C int huiwen (int);
Int main ()
{
int a;
For (a=100; a<1000; +)
{
If (sushu (a) & amp; & Huiwen (a))
Printf (" % d \ n ", a);
}

return 0;
}

Int sushu (int b)
{
Int e, f;
E=SQRT (b);
For (f=2; F<=e; F++)
If (b % f==0) return 0;
return 1;
}

Int huiwen (int) c
{
Int g, h;
G=c/100;
H=c % 10;
If (g==h)
return 1;
return 0;
}

CodePudding user response:

reference 1st floor forever74 response:
both wrong ah, verify prime function must to return 0 and return 1? So just logical,

The first right, the second is not correct

CodePudding user response:

reference 1st floor forever74 response:
both wrong ah, verify prime function must to return 0 and return 1? So just logical,

Right at the second custom function if judgment

CodePudding user response:

refer to the second floor QZJHJXJ response:
modify the first, for reference:
 # include 
#include
Int sushu b (int);
C int huiwen (int);
Int main ()
{
int a;
For (a=100; a<1000; +)
{
If (sushu (a) & amp; & Huiwen (a))
Printf (" % d \ n ", a);
}

return 0;
}

Int sushu (int b)
{
Int e, f;
E=SQRT (b);
For (f=2; F<=e; F++)
If (b % f==0) return 0;
return 1;
}

Int huiwen (int) c
{
Int g, h;
G=c/100;
H=c % 10;
If (g==h)
return 1;
return 0;
}

The second method, the second a custom function is what is wrong,

CodePudding user response:

Two methods there are bugs and errors, the first kind, the for (f=2; F<=e; F++) if (b % f==0) return 0; When, if b prime Numbers, if (b % f==0) return 0;
This statement will not be executed that means to the end of the function, also have no a clear return values, the main function of the if () judgment on what to judge,
This is a potential hazard, the second is wrongs, hidden trouble didn't rule out not only the first one, but also the judge if (b % f!=0) return 1; Conditions make the wrong, not
Prime Numbers also return into primes, if b=9, 9% 2!=0, return 1 immediately,
  • Related