# include & ltiostream & gt
使用命名空間std
# include & ltmath.h & gt
#定義MAXSIZE 20
typedef結構堆棧
{
char node[MAXSIZE];
int top
}棧;
int main()
{
堆棧s;
s . top =-1;
int n;
cout & lt& lt"請輸入壹個小數:"
CIN & gt;& gtn;
int m;
cout & lt& lt"請輸入要轉換的號碼:"
CIN & gt;& gtm;
int q = n;
而(n!=0)
{
q = n % m;
n = n/m;
s . top++;
如果(q & lt10)
s . node[s . top]= q+48;
其他
s . node[s . top]=(q-9)+64;
}
while(s . top & gt;=0)
{
cout & lt& lts . node[s . top-];
}
返回0;
}
遞歸算法:(不使用數組存儲)
# include & ltiostream & gt
使用命名空間std
#定義N 8
void print(int M);
int main()
{
打印(100);
返回0;
}
無效打印(整數)
{
int n = M % N
M = M/N;
如果(M!=0)
打印(M);
cout & lt& ltn;
}