#define N 8
void tran(int num,int k)
{
int arr[N],i;
for (i=0;i
arr[i]=num%k;
num=num/k;
if (num==0)
break;
}
printf("转换为%d进制数为: ",k);
for (;i>=0;i--)
switch (arr[i])
{
case 10: printf("A");break;
case 11: printf("B");break;
case 12: printf("C");break;
case 13: printf("D");break;
case 14: printf("E");break;
case 15: printf("F");break;
default: printf("%d",arr[i]);
}
printf("\n\n\n");
}
void main()
{
int num,choo;
loop: printf("请选择功能:0.退出 1.十进制转二进制 2.十进制转八进制 3.十进制转十六进制\n");
scanf("%d",&choo);
switch (choo)
{
case 1:
printf("请输入要转换的十进制数:");
scanf("%d",&num);
tran (num,2);
goto loop;
case 2:
printf("请输入要转换的十进制数:");
scanf("%d",&num);
tran (num,8);
goto loop;
case 3:
printf("请输入要转换的十进制数:");
scanf("%d",&num);
tran (num,16);
goto loop;
case 0:break;
default :
printf("输入有误!请重新输入!\n");
goto loop;
}
}