程序代码:
#include <stdio.h>
double pn( unsigned n, double x )
{
if( n == 0 )
return 1;
if( n == 1 )
return x;
return ((2*n-1)*x*pn(n-1,x)-(n-1)*pn(n-2,x))/n;
}
int main( void )
{
double x;
if( scanf("%lf",&x) != 1 )
return 1;
for( unsigned i=1; i!=21; ++i )
printf( "P%u(%lg) = %lf\n", i, x, pn(i,x) );
return 0;
}
输入 1
P1(1) = 1.000000
P2(1) = 1.000000
P3(1) = 1.000000
P4(1) = 1.000000
P5(1) = 1.000000
P6(1) = 1.000000
P7(1) = 1.000000
P8(1) = 1.000000
P9(1) = 1.000000
P10(1) = 1.000000
P11(1) = 1.000000
P12(1) = 1.000000
P13(1) = 1.000000
P14(1) = 1.000000
P15(1) = 1.000000
P16(1) = 1.000000
P17(1) = 1.000000
P18(1) = 1.000000
P19(1) = 1.000000
P20(1) = 1.000000
输入 1.23
P1(1.23) = 1.230000
P2(1.23) = 1.769350
P3(1.23) = 2.807167
P4(1.23) = 4.715416
P5(1.23) = 8.194196
P6(1.23) = 14.548399
P7(1.23) = 26.209104
P8(1.23) = 47.714896
P9(1.23) = 87.560627
P10(1.23) = 161.685779
P11(1.23) = 300.067037
P12(1.23) = 559.196076
P13(1.23) = 1045.728838
P14(1.23) = 1961.364694
P15(1.23) = 3688.111660
P16(1.23) = 6950.451699
P17(1.23) = 13124.061641
P18(1.23) = 24824.065265
P19(1.23) = 47026.847403
P20(1.23) = 89211.031495
听说谭教主的经书中把公式抄错了