十进制转N进制

输入一个十进制数,将其转换成N进制数(1<= N <= 16)

#include <stdio.h>

/* This function is used to convert the number 
 * "num" is the number you want to convert
 * "n" is the N 
 */
void convert(int num, int n)
{
    int out_num;
    if ((out_num = num / n) != 0) 
        convert(out_num, n);
    printf("%d", num % n);

}
int main()
{
    int num, n;
    printf("Please input the number of N: \n");
    scanf("%d", &n);
    printf("Please input the number you want to convert: \n");
    scanf("%d", &num);
    convert(num, n);
    putchar('\n');
    return 0;

测试结果:

posted on 2012-09-09 19:52  初级业余程序员  阅读(508)  评论(0)    收藏  举报

导航