问题描述:
编写递归函数,函数应该和下面的函数原型匹配:
int hermite(int n,int x)
Hermitee Polynomials(厄密多项式)是这样定义的:
n <= 0; 1;
Hn(x) = n = 1; 2x;
n >= 2; 2xHn-1(x)-2(n-1)Hn-2(x);
\
代码如下:
/*编写递归函数,函数应该和下面的函数原型匹配: int hermite(int n,int x) Hermitee Polynomials(厄密多项式)是这样定义的: n <= 0;1 Hn(x) = n = 1;2x; n >= 2;2xHn-1(x)-2(n-1)Hn-2(x);**/ #include<stdio.h> int Hermite(int n,int x) { if(n <= 0) return 1; else if(n == 1) return 2*x; else return 2*x*Hermite(n-1,x) - 2*(n-1)*Hermite(n-2,x); } int main() { int n; int x; int i = 1; while(i) { printf("Please input n and x:\n"); scanf("%d%d",&n,&x); printf("Hn(x) = %d\n",Hermite(n,x)); printf("if you want to continue :1 if you want to break:0\n"); scanf("%d",&i); } return 0; }
原文地址:http://blog.csdn.net/live_wyq/article/details/45606093