C语言编程~~~~编制不同数制间的转换程序。

来源:百度知道 编辑:UC知道 时间:2024/05/23 17:43:11
要求提供输入输出界面,当输完一个任意十进制数字,程序能自动将其转化为另外的数制表示的值,包括二进制、八进制和十六进制,其中转化用算法实现而不是用printf函数显示。

#include "stdio.h"

main()
{
unsigned long a,temp;
char b[64];
char o[21];
char h[16];
int i;

printf("Input number:");
scanf("%ld",&a);

temp=a;
i=63;
while(temp)
{
b[i]=temp%2+'0';
temp/=2;
i--;
}
printf("Bin:");
i++;
while(i<64)
{
printf("%c",b[i]);
i++;
}
printf("\n");

temp=a;
i=20;
while(temp)
{
o[i]=temp%8+'0';
temp/=8;
i--;
}
printf("Oct:");
i++;
while(i<21)
{
printf("%c",o[i]);
i++;
}
printf("\n");

temp=a;
i=15;
while(temp)
{
int x=temp%16;
if(x<10) h[i]=x+'0';
else h[i]=x-10+'A';
temp/=16;
i--;
}<