http://blog.csdn.net/e_wsq/article/details/14503675
递归方法解决10进制向其他进制转换的问题;
#include <stdio.h> void fun_1(int n); void fun_2(int n); void fun_4(int m); int main(){ fun_1(10); printf(" "); fun_2(32); printf(" "); fun_4(170); printf(" "); return 0; } //十进制转二进制 void fun_1(int n){ if(n<2){ printf("%d",n); }else if(n>=2){ fun_1(n/2); printf("%d",n%2); } } //十进制转八进制 void fun_2(int n){ if(n<8){ printf("%d",n); }else if(n>=8){ fun_2(n/8); printf("%d",n%8); } } //十进制转十六进制 void fun_3(int n){ switch (n){ case 10: printf("%c",'A'); break; case 11: printf("%c",'B'); break; case 12: printf("%c",'C'); break; case 13: printf("%c",'D'); break; case 14: printf("%c",'E'); break; case 15: printf("%c",'F'); break; default : printf("%d", n);; } } void fun_4(int m){ if(m<16){ fun_3(m); }else if(m>=16){ fun_4(m/16); fun_3(m%16); } }