Home > Back-end >  The Fibonacci sequence and the number of calls the function
The Fibonacci sequence and the number of calls the function

Time:11-12

Which big help the younger brother

CodePudding user response:

Give you a sample

 int gcount=0; 

Long long getp (int n) {
Gcount++;
If (n<1) return 1;
Else if (n==1) return 7;
Else if (n==2) return 11;
Return getp getp (n - 1) + (n - 2);//here is called recursive twice, so low efficiency
}

Int main () {
int n;
The scanf (" % d ", & amp; N);
Getp (n);
Printf (" % d \ n ", gcount);
return 0;
}
  • Related