pex10_5.cpp
来自「数据结构C++代码,经典代码,受益多多,希望大家多多支持」· C++ 代码 · 共 50 行
CPP
50 行
#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 + =
减小字号Ctrl + -
显示快捷键?