十进制转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;
测试结果:

浙公网安备 33010602011771号