Sam*_*kar 1 c++ recursion function
如何return((count-2)+(count-1))在以下cpp程序中运行?给定代码的ans 是-18.如何在不运行代码的情况下知道ans并且从两个中调用function count(n-2),count(n-1)哪个首先被调用,如何确定?
#include <iostream>
using namespace std;
int count(int n);
int main() {
int n, m;
n = 4;
m = count(n);
cout << m;
}
int count(int n)
{
if (n<0)
{
return n;
}
else
{
return (count(n - 2) + count(n - 1));
}
}
Run Code Online (Sandbox Code Playgroud)