#include<stdio.h>
int main()
{
char ch;
long long int a=0;
while(ch=getchar(),ch!='\n')
a=a*2+(ch-'0');
printf("%lld",a);
return 0;
}
为什么会答案错误
...全文
3341打赏收藏
C语言二进制转化为十进制
输入为一个二进制大整数(大整数大于0,不带符号,无前导0,至少1位数字,且不超过100位数字)。要求将该整数转换成十进制数,并输出。 建议:用字符数组存储大整数。 #include int main() { char ch; long long int a=0; while(ch=getchar(),ch!='\n') a=a*2+(ch-'0'); printf("%lld",a); return 0; } 为什么会答案错误