沈阳浑南规划图:求用C语言编写的10进制数到N进制数的转换程序

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/06 12:03:58
用C语言编写,完整的程序代码,用求商数取余法,将余数压到堆栈里,最后弹出结果。

这个程序只能转化成1到16进制数
#include <stdio.h>
void main()
{
long m;
int i=0,d,n,a[50],b[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

printf("please input the munber:\n");
scanf("%ld",&m);

printf("please input the base:\n");
scanf("%d",&n);

do{a[i]=m%n;i++;}while((m/=n)!=0);

printf("the new number is:\n");

for(--i;i>=0;i--)
{d=a[i];printf("%c ",b[d]);
}
printf("\n");
}

我也是刚刚学C,还请高手多多指教!!在VC上已经运行成功!