典型的递归求解程序
1: #include <stdio.h>
2:
3: float Rand(int n, float x)
4: {
5: if (n == 0)
6: return 1;
7: else if(n == 1)
8: return x;
9: else
10: return ( (2*n-1) * x - Rand(n-1, x) - (n-1) * Rand(n-2, x)) / n ;
11: }
12:
13: int main()
14: {
15: int n;
16: float x, p;
17: printf("Input n\n");
18: scanf("%d", &n);
19: printf("Input x\n");
20: scanf("%f", &x);
21:
22: p = Rand(n, x);
23: printf("p is %f", p);
24: getchar();
25: return 0;
26: }