#include <stdio.h>
int hermit(int n, int x)
{
if(n<=0)
return 1;
if (n==1) return 2*x;
return (2*x*hermit(n-1,x)-2*(n-1)*hermit(n-2,x));
}
int hermit2(int n,int x)
{
//int result=2*x;
int prev=1,next;
int result=2*x;
if(n<=0) return prev;
while(n>1)
{
next=prev;
prev=result;
result=2*x*prev-2*(n-1)*next;
n--;
}
//
return result;------>去掉了!!!
}
int main()
{
int t;
t=hermit2(4,2);
printf("the answer is %d\n",hermit(4,2));
printf("the answer is %d\n",hermit2(2,8));
printf("the answer is %d\n",t);
printf("the answer is %d\n",hermit2(0,8));
return 0;
}
结果都一样:
the answer is 76
the answer is 254
the answer is 76
the answer is 1
环境:intel dsktop linux+gcc 4.3.0
难道编译器有智能?