Changed after the original forget, so the title is the original wrong topic change later, but there are still problems
Topics are as follows:
#include
Int BinToDec (/* */int []/* */p)
{
Int sum=0, I=0;
While (p [I]!='\ 0')
{
Sum=sum */* */+ 2 p [I] 0/* */.
I++ I;
}
return sum;
}
Void main ()
{
Int street [80], s;
Printf (" Enter only 0, 1 string: ");
The scanf (" % s ", STR);
S=BinToDec (/* */STR/* */);
Printf (" Bin=% s<==& gt; Dec=% d \ n ", STR, s);
}
CodePudding user response:
Reference:# include
Int BinToDec (char []) p
{
Int sum=0, I=0;
While (p [I]!='\ 0')
{
Sum=sum * 2 + p [I] - '0';
i++;
}
return sum;
}
Int main ()
{
Int s;
Char STR [80].
Printf (" Enter only 0, 1 string: ");
The scanf (" % s ", STR);
S=BinToDec (STR);
Printf (" Bin=% s<=& gt; Dec=% d \ n ", STR, s);
return 0;
}
CodePudding user response:
To join https://bbs.csdn.net/topics/399167039CodePudding user response:
# include & lt; stdio.h>
Int main ()
{
Int remainder, number=0, decimal_number=0, temp=1;
Printf (" \ n the Enter any binary number=");
The scanf (" % d ", & amp; Number);
//to Iterate over the number until the end.
While (number & gt; 0)
{
Remainder %=number 10;
Number=number/10;
Decimal_number +=remainder * temp;
Temp=temp * 2;//2 as the power of 2
}
Printf (" % d \ n ", decimal_number);
}
Hope to adopt, can focus on direct messages I don't understand,