試題 算法訓練 十進制數轉八進制數
資源限制
時間限制:1.0s 內存限制:512.0MB
編寫函數把一個十進制數輸出其對應的八進制數。
樣例輸入
9274
樣例輸出
22072
#include<stdio.h>
#include<string.h>
int main()
{
int a[20];
int i,j,n,s,l;
scanf("%d",&n);
i=0;
while(n>0)
{
a[i]=n%8;
n=(n-n%8)*1.0/8;//重點在這哦
i++;
}
for(j=i-1;j>=0;j--)
{
printf("%d",a[j]);
}
return 0;
}