这是我的“C++ 入门”类(class)。我需要
Write a program that uses a recursive function double_all_digit that doubles all digit from an integer. For example,
double_all_digits(101)
will return110011
我下面的代码只适用于一个数字;我不知道如何进行:
int double_all_digit(int x)
{
if(x < 10)
return (x*10) + x;
}
最佳答案
你有基本情况;现在进行递归。
- 将数字拆分为 1 的数字(使用模数)和其余数字。
- 重复休息;你的结果是所有数字都加倍的数字。
- 将该结果乘以 100;加上 1 的数字的 11 倍。
- 将该值返回上一级。
关于C++:使用递归加倍数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43690676/