C语言用递归方法求n阶勒让德多项式的值
答案:3 悬赏:60 手机版
解决时间 2021-03-22 01:03
- 提问者网友:謫仙
- 2021-03-21 14:42
C语言用递归方法求n阶勒让德多项式的值
最佳答案
- 五星知识达人网友:拾荒鲤
- 2021-03-21 16:20
#include
#include
float myfunction(int n,int x)
{
if (0 == n)
{
return 1;
}
else if (1 == n)
{
return x;
}
else
{
return ((2 * n - 1) * x - myfunction(n - 1 , x) - (n - 1) * myfunction(n - 2, x)) / n; //递归的运算步骤
}
}
int main()
{
int n,x;
float result; //定义一个结果变量
printf("please inputa n,x:");
scanf("%d,%d",&n,&x);
result = myfunction(n,x);
printf("the result is : %f
",result);
system("pause");
return 0;
}
#include
float myfunction(int n,int x)
{
if (0 == n)
{
return 1;
}
else if (1 == n)
{
return x;
}
else
{
return ((2 * n - 1) * x - myfunction(n - 1 , x) - (n - 1) * myfunction(n - 2, x)) / n; //递归的运算步骤
}
}
int main()
{
int n,x;
float result; //定义一个结果变量
printf("please inputa n,x:");
scanf("%d,%d",&n,&x);
result = myfunction(n,x);
printf("the result is : %f
",result);
system("pause");
return 0;
}
全部回答
- 1楼网友:荒野風
- 2021-03-21 17:22
不知道
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯