#include
void dec2n(int x,int n)
{int a[33],i;
for(i=0;x;x/=n)a[i++]=x%n;
for(i--;i>=0;i--)
if(a[i]<10)printf("%d",a[i]);
else printf("%c",a[i]+55);
printf("\n");
}
int main()
{int x;
scanf("%d",&x);
printf("%d的八进制:",x);dec2n(x,8);
printf("%d的十六进制:",x);dec2n(x,16);
return 0;
}
#include
const int maxn = 128;
const int index8 = 8;
const int index16 =16;
int main()
{
int Array8[maxn];
int Array16[maxn];
int n, cot8 = 0;
scanf("%d", &n);
int m = n, cot16 = 0;
while(n)
{
Array8[cot8++] = n % index8;
n /= index8;
}
while(m)
{
Array16[cot16++] = m % index16;
m /= index16;
}
int i;
for(i = cot8 - 1; i >= 0; i--)
printf("%d", Array8[i]);
puts("");
for(i = cot16 - 1; i >= 0; i--)
//************************这里有改动****************************
if(Array16[i]<10){ //小于10的情况
printf("%d", Array16[i]);
}else{ //大于10 的情况 ASCII码的知识
printf("%c",Array16[i]-10+'A');
}
//*********************************************************************
printf("\n");
return 0;
}
#include
const int maxn = 128;
const int index8 = 8;
const int index16 = 16;
int main()
{
int Array8[maxn];
int Array16[maxn];
int n, cot8 = 0;
scanf("%d", &n);
int m = n, cot16 = 0;
while(n)
{
Array8[cot8++] = n % index8;
n /= index8;
}
while(m)
{
Array16[cot16++] = m % index16;
m /= index16;
}
int i;
for(i = cot8 - 1; i >= 0; i--)
printf("%d", Array8[i]);
puts("");
for(i = cot16 - 1; i >= 0; i--)
printf("%d", Array16[i]);
return 0;
}