Recursive method
/*
==================================================================
Title: F (60), where F (n) is defined such as the following:
F (0) = 0;
F (1) = 1;
F (2n) =f (n) +3;
F (2n+1) =f (n) +f (2n-1).
==================================================================
*/
#include <stdio.h>
Double F (int n)
{
if (n==0) return 0;
else if (n==1) return 1;
else if (n%2==0) return F (N/2) +3;
else if (n%2!=0)
Return F ((n-1)/2) +f (n-2);
}
void Main ()
{
int n;
float p;
printf ("n=");
scanf ("%d", &n);
P=f (n);
printf ("F (%d) =%.2lf\n", n,p);
}
/*
======================================================================
Evaluation:
In the third equation. Make t=2n, so t%2==0,n=t/2;
In the Forth equation, the t=2n+1, so T is an odd number, then n= (t-1)/2,2n-1=t-2; (n as T in the program)
Creating a recursive relationship is very easy to write.
========================================================================
*/
C language Function call 17-a call to a function in recursion (2)