有人可以向我解释这究竟是如何加起来26?
我对"双重呼叫"感到困惑.也许我只是不理解递归以及我认为我做的.
#include <iostream>
using namespace std;
int rec(int * N, int max) {
if (max < 0)
return 0;
return N[max] + rec(N, max - 1) + rec(N, max - 2);
}
int main() {
const int max = 5;
int N[] = { 1, 2, 3, 4, 5 };
int f = rec(N, max - 1);
cout << f << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)