📄 pex10_5.cpp
字号:
#include <iostream.h>
#pragma hdrstop
// output N in base B <= 10
void intout(long N, int B)
{
// N/B contains the left-most digits of the number
// output them. this is the recursive step
if (N/B != 0)
intout(N/B,B);
// output the right-most digit (stopping condition)
cout << N % B;
}
void main(void)
{
long N;
int B;
// read 5 number N, base B pairs. output
// N in base B
for(int i=0;i < 5;i++)
{
cout << "Enter number N and base B: ";
cin >> N >> B;
cout << N << " in base " << B << " is ";
intout(N,B);
cout << endl << endl;
}
}
/*
<Run>
Enter number N and base B: 25 2
25 in base 2 is 11001
Enter number N and base B: 3557 8
3557 in base 8 is 6745
Enter number N and base B: 511 4
511 in base 4 is 13333
Enter number N and base B: 511 8
511 in base 8 is 777
Enter number N and base B: 789453 9
789453 in base 9 is 1432830
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -