#include
#include
int convertBinaryToDecimal(long long n);
int main()
{
long long n;
printf("输入一个二进制数: ");
scanf("%lld", &n);
printf("二进制数 %lld 转换为十进制为 %d", n, convertBinaryToDecimal(n));
return 0;
}
int convertBinaryToDecimal(long long n)
{
int decimalNumber = 0, i = 0, remainder;
while (n!=0)
{
remainder = n%10;
n /= 10;
decimalNumber += remainder*pow(2,i);
++i;
}
return decimalNumber;
}
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(void)
{
int n[50],t=0,sum=0;
int num,num1;
puts("请输入一个二进制数");
scanf("%d", &num);
num1 = num;
while (num > 0) {
n[t] = num % 10;
num /= 10;
t++;
}
for (int i = 0; i < t; i++) {//最后t没用
sum += n[i]*pow(2,i);
}
int main()
{
long long n;
printf("输入一个二进制数: ");
scanf("%lld", &n);
printf("二进制数 %lld 转换为十进制为 %d", n, convertBinaryToDecimal(n));
return 0;
}
int convertBinaryToDecimal(long long n)
{
int decimalNumber = 0, i = 0, remainder;
while (n!=0)
{
remainder = n%10;
n /= 10;
decimalNumber += remainder*pow(2,i);
++i;
}
return decimalNumber;
}
登录后提交答案