#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
//代码复用0^0
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++) {
sum += n[i] * pow(8, i);
}
//以10进制为媒介 8->10->2
int num2 = sum, k = -1, n1[50];//两套组合
do {
k++;
n1[k] = sum % 2;
sum /= 2;
} while (sum > 0);//商大于0
printf("%d的二进制为:\n", num1);
for (int i = k; i >= 0; i--) {//--
printf("%d", n1[i]);
}
登录后提交答案