#include<stdio.h>
#include<stdlib.h>
int main()
{
char c[120];
int i,a=0;
printf("输入一个二进制数:");
scanf("%s",c);
for(i=0;c[i]!='\0';i++)
{
a=a<<1;
if(c[i]=='1')
a++;
}
printf("%o\n",a);
return 0;
}
![这里写图片描述](https://img-blog.csdn.net/20180108112644900?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFuZzA1MTMwOA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
void main()
{
int num;
int m,c[20];
char A='\65',B='\66',C='\67',D='\68',E='\69',F='\70';
printf("输入一个二进制数:");
scanf("%d",&num);
for(m=0;m>=0;m++)
{
c[m]=num%16;
if(num/16==0)
break;
num=num/16;
}
for(;m>=0;m--)
{
if(c[m]==10)
printf("A");
else if(c[m]==11)
printf("B");
else if(c[m]==12)
printf("C");
else if(c[m]==13)
printf("D");
else if(c[m]==14)
printf("E");
else if(c[m]==15)
printf("F");
}
printf("\n");
}
![这里写图片描述](https://img-blog.csdn.net/20180108112737811?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGFuZzA1MTMwOA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)