#include <stdio.h>
int main()
{
int transfer(int x);
int face(int n);
int x;
printf("请输入一个十进制数:");
scanf("%d",&x);
printf("转换成二进制数:%d\n",transfer(x));
printf("进阶之递归转换结果:%d\n",fact(x));
}
int transfer(int x)
{
int p=1,y=0,yushu;
while(1)
{
yushu=x%2;
x/=2;
y+=yushu*p;
p*=10;
if(x<2)
{
y+=x*p;
break;
}
}
return y;
}
int fact(int n) {
if(n<2) //将 2 换成其它数如 8 就可输出 8 进制的结果
return n;
else{
return fact(n/2)*10+n%2;
}
}