Home > Back-end >  Why is my code in vs and devc inconsistent results run?
Why is my code in vs and devc inconsistent results run?

Time:12-04

# include & lt; Stdio. H>
# include & lt; Math. H>
Int isPrime (int n);
Int main ()
{
Int n, I, p, q;
The scanf (" % d ", & amp; n);
For (I=2; I & lt;=n/2; I++) {
If (isPrime (I) & amp; & IsPrime (n - I)) {
Printf (" % d=% d + % d ", n, I, n - I);
break;
}
}

return 0;
}
Int isPrime (int n)
{
Int I, div.
For (div=2; Div & lt;=SQRT (n); Div++) {
{if (n % div==0)
break;
return 0;
}
If (div==n)
return 1;
}
}

CodePudding user response:

The result is not the same as that you have ambiguity code, must be modified,,,

CodePudding user response:

The building Lord primes judging function has a problem
reference
int isPrime (int n)
{
Int I, div.
For (div=2; Div & lt;=SQRT (n); Div++) {
{if (n % div==0)
break;
return 0;
}
If (div==n)
return 1;
}

Modified as follows, for your reference:
 int isPrime (int n) 
{
For (int div=2; Div & lt;=SQRT (n); Div++)
If (n % div==0)
Return 0;
Return 1;
}

CodePudding user response:

Missed the above 1, revision:
 int isPrime (int n) 
{
If (n<2) return 0;
For (int div=2; Div & lt;=SQRT (n); Div++)
If (n % div==0)
Return 0;
Return 1;
}
  • Related