码迷,mamicode.com
首页 > 其他好文 > 详细

用递归函数计算厄密多项式

时间:2014-11-21 21:52:40      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   sp   div   2014   log   

《C和指针》第7章第1道编程题:

Hermite Polynomials(厄密多项式)是这样定义的:

 

bubuko.com,布布扣

例如,H3(2)的值是40。请编写一个递归函数,计算Hn(x)的值。函数原型为:

int hermite( int n, int x );

 

 1 /*
 2 ** 计算Hermite Polynomials(厄密多项式)的值
 3 */
 4 
 5 #include <stdio.h>
 6 
 7 int hermite( int n, int x );
 8 
 9 int 
10 main()
11 {
12     int n, x;
13     scanf( "%d%d", &n, &x );
14     printf( "%d", hermite( n, x ) );
15     return 0;
16 }
17 
18 /*
19 ** 计算厄密多项式的值,递归函数版本
20 */
21 int 
22 hermite( int n, int x )
23 {
24     int result;
25     
26     if( n <= 0 )
27         result = 1;
28     else {
29         if( n == 1 )
30             result = 2 * x;
31         else
32             result = 2 * x * hermite( n - 1, x ) 
33                 - 2 * ( n - 1 ) * hermite( n - 2, x );
34     }        
35     return result;
36 }

 

用递归函数计算厄密多项式

标签:style   blog   http   io   color   sp   div   2014   log   

原文地址:http://www.cnblogs.com/zouhongmey/p/4113886.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!