程序填空题:请把一个十进制数N转换为d进制数,并输出。
请把一个十进制数N转换为d进制数,并输出。
```c++
#include
#include
using namespace std;
int main()
{
stacks;
int e;
int N,d;
cin>>N>>d;
if(d==2 ||d==8|| d==16)
{
while(N)
{
@@[s.push(N%d)](1); //将N与d求余得到的d进制数压入栈
N=N/d;
}
}
while(!s.empty())
{
@@[e=s.top()](1); //获取栈顶元素e
@@[s.pop()](1); //弹出栈顶元素
if(e>=10)
cout< else
cout< }
cout< return 0;
}
```
答案:
第1空:s.push(N%d)
第2空:e=s.top()
第3空:s.pop()
```c++
#include
#include
using namespace std;
int main()
{
stack
int e;
int N,d;
cin>>N>>d;
if(d==2 ||d==8|| d==16)
{
while(N)
{
@@[s.push(N%d)](1); //将N与d求余得到的d进制数压入栈
N=N/d;
}
}
while(!s.empty())
{
@@[e=s.top()](1); //获取栈顶元素e
@@[s.pop()](1); //弹出栈顶元素
if(e>=10)
cout<
cout<
cout<
}
```
答案:
第1空:s.push(N%d)
第2空:e=s.top()
第3空:s.pop()