|
RT. 当展开数比基数小的时候返回. 1#include <stdio.h> 2 3// 得到整数u的以基数n的展开式 4void f(unsigned int u, unsigned int n) 5{ 6 if (u < n) 7 { 8 return; 9 } 10 unsigned int i, k; 11 12 printf("%d = ", u); 13 k = 0; 14 while (u) 15 { 16 i = u % n; 17 if (i) 18 { 19 if (!k) 20 { 21 printf("%d*%d^%d", i, n, k); 22 } 23 else 24 { 25 printf(" + %d*%d^%d", i, n, k); 26 } 27 } 28 29 u = u / n; 30 k += 1; 31 } 32} 33 34int main() 35{ 36 f(165, 8); 37 return 0; 38} 39
|