C++ 使用递归将数字转换为具有不同基数的另一个数字?
我正在使用递归将一个数字转换成另一个具有不同基数的数字,但我的代码中存在一个问题。我的代码不符合我的要求。请检查并告诉我问题出在哪里? 谢谢C++ 使用递归将数字转换为具有不同基数的另一个数字?,c++,recursion,C++,Recursion,我正在使用递归将一个数字转换成另一个具有不同基数的数字,但我的代码中存在一个问题。我的代码不符合我的要求。请检查并告诉我问题出在哪里? 谢谢 #包括 使用名称空间std; int基函数(int,int); int main() { 整数,基数; 库特号码; coutbase; coutcoutnumber; coutbase; 虽然你的思维方向正确,但你在逻辑上犯了一个小错误 if(n==1) return n; else { baseFunction(n/b,b); c
#包括
使用名称空间std;
int基函数(int,int);
int main()
{
整数,基数;
库特号码;
coutbase;
coutcoutnumber;
coutbase;
虽然你的思维方向正确,但你在逻辑上犯了一个小错误
if(n==1)
return n;
else
{
baseFunction(n/b,b);
cout<<n%b;
}
if(n==1)
返回n;
其他的
{
基本功能(n/b,b);
coutNumbers没有“基数”。你手上手指的基数是多少?基数可以是3、8、16等。数字没有基数;数字的文本表示有基数。谢谢你的回答。你能给我这个程序的正确代码吗?
cout<<"Enter number: ";
//enters NUMBER
cin>>number;
cout<<"Enter base: ";
//enters BASE
cin>>base;
cout<<"OutPut "<<number<<" is ";
//function, that returns int, returns it to nothing, so nothing changes
baseFunction(number,base);
//BASE unaffected, since function did nothing
cout<<" in base "<<base<<endl;
if(n==1)
return n;
else
{
baseFunction(n/b,b);
cout<<n%b;
}
if(n>0)
{
baseFunction(n/b,b);
cout<<n%b;
}
else
{
return;
}