自由尋覓快樂別人從沒法感受

0%

C语言学习第四章T3

题目:用递归方法求n解勒让德多项式的值

公式详情:https://baike.baidu.com/item/勒让德多项式

主要代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# include <stdio.h>
# include <iostream>
float polya(float n,float x);

int main (void)
{
float x,n,y;
printf("input x:");
scanf("%f",&x);
printf("input n:");
scanf("%f",&n);
y=polya(n,x);
printf("answer:%f\n",y);
return 0;
}

float polya(float n,float x)

{
if (n==0)
{
return 1.0;
}
else if(n==1)
{
return x;
}
else
{
return ( (2.0*n-1.0)*x*polya(n-1.0,x) - (n-1.0)*polya(n-2.0,x) )/n;
}

}

运行结果: