Skip to content

Commit 7abda62

Browse files
authored
Update 计算厄密多项式.c
1 parent c2f51f9 commit 7abda62

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

经典项目/计算厄密多项式.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
#
1+
#include <stdio.h>
2+
3+
/**
4+
* 计算 Hermite polynomial 的值
5+
*
6+
* 输入:
7+
* n, x:用于标识值
8+
*
9+
* 输出:
10+
* polynomial的值(返回值)
11+
**/
12+
13+
int hermite( int n, int x )
14+
{
15+
// 处理不需要递归的特殊情况。
16+
if( n <= 0 )
17+
return 1;
18+
if( n == 1 )
19+
return 2 * x;
20+
21+
// 否则,递归地计算结果值。
22+
return 2 * x * hermite( n - l, x ) - 2 * ( n - 1 ) * hermite ( n - 2, x );
23+
}
24+
25+
int main()
26+
{
27+
printf("%d\n", hermite(3,2));
28+
29+
return 0;
30+
}

0 commit comments

Comments
 (0)