题目:将十进制数N转换成r进制的数,其转换方法利用辗转相除法:
思路:(1)将N%r入栈,将N/r代替N。
(2)将栈s中的内容一次出栈并输出。
例程:
#include<stdio.h>
#define L 20
main()
{int N,r;
int s[L],top;
int x,y;
top=-1;
printf("N=");
scanf("%d",&N);
printf("r=");
scanf("%d",&r);
while(N)
{s[++top]=N%r;
N=N/r;
}
while (top!=-1)
{x=s[top--];
if(x>9)
{y=x+55;
printf("%c\n",y);
}
else
printf("%d\n",x);
}
}