
在这个部分,我们将看到一个有趣的问题。假设给定一个数字。我们需要将这个数字增加1。这是一个非常简单的任务。但是在这里,我们将把数字作为一个数组放置。该数字的每个数字都被放置为数组的一个元素。如果数字是512,那么它将被存储为{5, 1, 2}。而且我们还必须使用递归方法增加数字。让我们看看算法以获得清晰的思路。
算法
increment(arr, n, index) −
Initially the default value of index is 0
begin
if index <h2>示例</h2><pre class="brush:php;toolbar:false;">#include <iostream>
#include <cmath>
#define MAX 20
using namespace std;
void increment(int num_arr[], int &n, int index = 0){
if(index = 0; i--){
cout <h2>输出</h2>
<pre class="brush:php;toolbar:false;">Initial Number: 1782698599
Final Number: 1782698600










