Verify whether n can be decomposed into two prime Numbers multiplication, is to return 1, no returns 0; Through the pointer x, y return decomposition of two prime Numbers For example 111 x=3=3 * 37 * and * y=37, the function returns the value 1
Why come out the debug an assertion failed
#include #include Int prime (int m) { Int k, flag=1; For (k=2; KIf (m % k==0) Flag=0; return flag; } Int fun (int n, int x, int * y) { Int k, flag=0; Int k2. K=2; Do { K2=n/k; If (k * k2==n) If (prime (k) & amp; & Prime (k2) & amp; & K{ Flag=1; * x=k; * y=k2. break; } K +=1; } While (k return flag; } The main () { int a,b; The FILE * out; Out=fopen (" C: \ \ KSWJJ \ \ 2454999999010001 \ \ out dat ", "w"); If (fun (111, & amp; A, & amp; B)) { Printf (" * 111=% d % d \ n ", a, b); Fprintf (out, "111=% d * % d \ n", a, b); } If (fun (11111, & amp; A, & amp; B)) { Printf (" * 11111=% d % d \ n ", a, b); Fprintf (out, "11111=% d * % d \ n", a, b); } If (fun (1111111, & amp; A, & amp; B)) { Printf (" * 1111111=% d % d \ n ", a, b); Fprintf (out, "1111111=% d * % d \ n", a, b); } The fclose (out); getchar();
}
CodePudding user response:
Where the assert? Said illegal access
CodePudding user response:
A and b to initialize a try
CodePudding user response:
Int fun (int n, int x, int * y) { Int k, flag=0; Int k2. K=2; Do { K2=n/k; If (k * k2==n) If (prime (k) & amp; & Prime (k2) & amp; & K{ Flag=1; * x=k;//here seems to use wild pointer, can't let the pointer to a local variable, because when the end of the function call will undo the local variables of memory space, and then you could use the pointer points outside the function in the variable, it is no good, * y=k2.//it is break; } K +=1; } While (k return flag; }
CodePudding user response:
The main ()//here seems should be int main () { int a,b; The FILE * out; Out=fopen (" C: \ \ KSWJJ \ \ 2454999999010001 \ \ out dat ", "w"); If (fun (111, & amp; A, & amp; B)) { Printf (" * 111=% d % d \ n ", a, b); Fprintf (out, "111=% d * % d \ n", a, b); }