【C语言】编写递归函数编写厄密多项式。

/*编写递归函数编写厄密多项式,函数应该和下面的函数原型匹配:
int hermite(int n, int x)
厄密多项式是这样定义的:
      n <= 0时,h(n(x)) = 1;
	  n = 1时,h(n(x)) = 2*x;
	  n >= 2时,h(n(x)) = 2*x*(h(n-1)(x)) - 2*(n-1)*(h(n-2)(x));
编写递归函数,函数应该和下面的函数原型匹配:
int hermite(int n, int x)*/

#include <stdio.h>

int hermite(int n, int x)
{
	int h = 0;
	if( n <= 0 )
		h = 1;
	else if( n == 1 )
		h = 2 * x;
	else
		h = 2 * x * hermite( n - 1, x ) - 2 * ( n - 1 ) * hermite( n - 2, x );
	return h;
}

int main()
{
	printf("%d\n",hermite(4,3));
	return 0;
}
<img src="http://img.blog.csdn.net/20150405212703924?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZG91ZG91d2ExMjM0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

时间: 2024-08-09 12:29:38

【C语言】编写递归函数编写厄密多项式。的相关文章

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

<C和指针>第7章第1道编程题: Hermite Polynomials(厄密多项式)是这样定义的: 例如,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

用c语言实现 Hermite Polynomials(厄密多项式)

编写递归函数,函数应该和下面的函数原型匹配: int hermite(int n, int x) #include<stdio.h> int main() { int hermite(int n, int x); printf("%d\n",hermite(2,1)); return 0; } int hermite(int n, int x) { int sum; if(n<=0) { sum=1; } else if(n==1) { sum=2*x; } else

【c语言】厄密多项式--用递归实现

/* 厄密多项式是这样定义的: n <= 0时,h(n(x)) = 1; n = 1时,h(n(x)) = 2*x; n >= 2时,h(n(x)) = 2*x*(h(n-1)(x)) - 2*(n-1)*(h(n-2)(x)); 编写递归函数,函数应该和下面的函数原型匹配: int hermite(int n, int x)*/ #include <stdio.h> int hermite(int n, int x) { int h = 0; if( n <= 0 ) h

【C语言】厄密多项式

#include<stdio.h> /* 厄密多项式 */ int hermite(int n, int x) { if(n<=0) return 1; else if(n==1) return 2*x; else if(n>=2) return 2*x*hermite(n-1,x)-2*(n-1)*hermite(n-2,x); } int main() { int n,x; puts("input N and X:"); scanf("%d%d&q

【C语言】 厄密多项式(递归函数)

所以他的递归函数为: <span style="font-size:18px;">#include<stdio.h> int hermite(int n,int x) { if (n<0) return 1; if (n=1) return 2*x; if (n>2) return 2*(hermite(n-1,x))-2*(n-1)*(hermite(n-2,x)); } int main() { hermite(1,2); printf(&quo

函数递归(厄密多项式)

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(1 == n) return 2*x; else return 2 * x * hermite(n-1, x) - 2 * (n-1) * hermite(n-2, x); } in

VHDL与Verilog硬件描述语言TestBench的编写

VHDL与Verilog硬件描述语言在数字电路的设计中使用的非常普遍,无论是哪种语言,仿真都是必不可少的.而且随着设计复杂度的提高,仿真工具的重要性就越来越凸显出来.在一些小的设计中,用TestBench来进行仿真是一个很不错的选择.VHDL与Verilog语言的语法规则不同,它们的TestBench的具体写法也不同,但是应包含的基本结构大体相似,在VHDL的仿真文件中应包含以下几点:实体和结构体声明.信号声明.顶层设计实例化.提供激励:Verilog的仿真文件应包括:模块声明.信号声明.顶层设

使用C语言为python编写动态模块(1)--从底层深度解析python中的对象以及变量

楔子 我们知道可以通过使用C语言编写动态链接库的方式来给python加速,但是方式是通过ctypes来加载,通过类CDLL将动态链接库加载进来得到一个对象之后,通过这个对象来调用动态链接库里面的函数.那么问题来了,我们可不可以使用C语言为python编写模块呢?然后在使用的时候不使用ctypes加载动态库的方式,而是通过python的关键字import进行加载. 答案是可以的,我们知道可以通过编写py文件的方式来得到一个模块,那么也可以使用C语言来编写C源文件,然后再通过python解释器进行编

每天一点GO语言——Linux环境下安装Go语言环境以及编写Go语言程序初体验

每天一点GO语言--Linux环境下安装Go语言环境以及编写Go语言程序初体验 一.安装Go语言环境 [[email protected] opt]# yum -y install wget git [[email protected] opt]# wget -c https://studygolang.com/dl/golang/go1.10.3.linux-amd64.tar.gz [[email protected] opt]# tar -zxvf go1.10.3.linux-amd64