This is my program:
#include
#include
Int main ()
{int I, n, t=0, sum=0, a [16]={0};
The scanf (" % d ", & amp; N); i=0;
While (n!=0)
{a [I]=n % 10, n=n/10; T++; i++;
}
for(i=0; i
}
Printf (" % d ", sum);
}
I don't know why but, seek advice,
CodePudding user response:
Enter a binary string, as a string processing, rather than an integerCodePudding user response:
#includeInt main ()
{
Int I, sum, [16] a={0};
Long n;
The scanf (" % ld ", & amp; N);
i=0;
While (n!=0)
{
A [I]=n % 10;
N=n/10;
i++;
}
Sum=0;
for(; i>=0; - I)
Sum=sum * 2 + a, [I].
Printf (" % d ", sum);
return 0;
}
CodePudding user response:
Above is a recursive solution, here is a recursive solution#include
Int btod (int d)
{
If (d<2)
return d;
The else
Return btod (d/10) * 2 + d % 10;
}
Int main ()
{
Int the sum, n;
The scanf (" % d ", & amp; N);
Sum=btod (n);
Printf (" % d ", sum);
return 0;
}
CodePudding user response:
N of type int is you use to store the binary number, you is equivalent to do such a thing, int n=100 billion; This already more than int can store the size of the data, will go wrong, of course, you must make a mistake, the data is too large or is to live for a long time I see, ha ha, but on good friend right, suggest you take a binary number as string processing, counted string length, well done,CodePudding user response:
The input as an integer, should as a string for processing, it can be stored in the read in a character array,