Problem B: 將十進位制數對應的八進位制、十六進位制、十進位制數輸出
阿新 • • 發佈:2018-11-17
Problem B: 將十進位制數對應的八進位制、十六進位制、十進位制數輸出
Time Limit: 1 Sec Memory Limit: 128 MB
Description
輸入一個十進位制數,轉換為對應的八進位制、十六進位制、十進位制數輸出
Input
輸入一個十進位制數
Output
輸出該十進位制數對應的八進位制、十六進位制、十進位制數
Sample Input
10
Sample Output
oct:12
hex:a
dec:10
HINT
使用輸出格式控制符 dec oct hex
參考答案:
#include<stdio.h>
int main()
{
int a,i,m,n;
int b[20];
scanf("%d",&a);
m=a;
n=a;
for(i=0;m>0;i++)
{
b[i]=m%8;
m=m/8;
}
printf("oct:");
for(i--;i>=0;i--)
{
printf("%d",b[i]);
}
printf("\n");
printf("hex:%x",n);
printf("\n");
printf("dec:%d",a);
return 0;
}