7月 15, 2010

十進位(Decimal) 轉成 八進位(Octal)


int main()
{
int r, num10, num8, multi;
r=num8=0;
multi=1; /* for counting power(10,i) */

printf ("input decimal: ");
scanf ("%d", &num10);

while (num10 > 0)
{
r = num10 % 8;
num8 = num8 + (multi * r);
multi = multi * 10;
num10 = num10/8;
}

return 0;
}

沒有留言:

張貼留言