Home > Back-end > Consult converts decimal positive integer to a binary when the cause of the error
Consult converts decimal positive integer to a binary when the cause of the error
Time:06-02
My freshman year, suddenly thought of wrote this source, but don't know where I went wrong, #include Int main () { int a; Void DecimalToBinaryConversion (int n); Printf (" please enter a decimal positive integers: "); The scanf (" % d ", & amp; A); Printf (" the corresponding binary number is: "); DecimalToBinaryConversion (a); return 0; }
Void DecimalToBinaryConversion (int n) [32] {short int x={0}; int i=0; for(i=0; i<=31; I++) [I] {x=n % 2; If (n/2! N=n=1)/2; The else x + 1] [I=n/2; } For (I=31; I>=0; I -) { If (x [I]==0) continue; Else for (; I>=0; I -) Printf (" % d ", x [I]); } }
CodePudding user response:
Inside the function static variables should be used