可以用函数itoa将十进制数转换成对应二进制数的字符串,然后在输出该字符串。
int num= 15;
char str[8];
itoa(num,str,2);
printf(str);
其中itoa函数的第三个参数就是你要转换的进制数。
#include
void main()
{
int a=12345;
printf("a=%o\n",a); //%o表示以八进制输出。
}
int i=0,j,m,n,md;
int bt[20]={0};
md=35;//要转换的数
printf("\n");
n=md;
do
{
m=n;
bt[i++]=m%2;
n=m/2;
}while(m!=0);
for(j=7;j>=0;j--)
{
printf("%d",bt[j]);
}
printf("\n");
贴不下又不能删,百度怎么这样啊