为了让程序清单9.8中的to_binary()函数更通用,编写一个to_base_n() 函数接受两个在2~10范围内的参数,然后以第2个参数中指定的进制打印第 1个参数的数值。

#include <stdio.h>
void to_base_n(int n,int m);
void main() {
	to_base_n(129,8);//这里可以自行输入值
}
void to_base_n(int n, int m) {
	int x,y;
	y = n % m;
	x = n / m;
	if (x >= m)
		to_base_n(x, m);//一个递归函数,反复执行。
	else printf("%d", x);
		printf("%d", y);
	
	}
发布了3 篇原创文章 · 获赞 2 · 访问量 30

猜你喜欢

转载自blog.csdn.net/qq_44720864/article/details/105323366