第1个回答 2015-06-15
#include <stdio.h>
#include <math.h>
#include <string.h>
char hashcode[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void toBinary(int n)
{
int s[1000],top=-1;
if(!n)
{
printf("%d\n",0);
return;
}
while(n)
{
s[++top]=n%2;
n/=2;
}
while(top!=-1)
printf("%d",s[top--]);
printf("\n");
}
void toOctonary(int n)
{
char s[1000];
int top=-1;
if(!n)
{
printf("%d\n",0);
return;
}
while(n)
{
s[++top]=hashcode[n%8];
n/=8;
}
while(top!=-1)
printf("%c",s[top--]);
printf("\n");
}
void toHex(int n)
{
char s[1000];
int top=-1;
if(!n)
{
printf("%d\n",0);
return;
}
while(n)
{
s[++top]=hashcode[n%16];
n/=16;
}
while(top!=-1)
printf("%c",s[top--]);
printf("\n");
}
int main()
{
char number[100];
int n=0;
unsigned int i;
scanf("%s",number);
for(i=0;i<strlen(number);i++)
n+=(number[i]-'0')*pow(8,strlen(number)-i-1);
printf("十进制:%d\n",n);
printf("二进制:");
toBinary(n);
printf("八进制:");
toOctonary(n);
printf("十六进制:");
toHex(n);
return 0;
}本回答被网友采纳