大神帮我再改一个,作业,谢谢了// recursive.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"using namespace std;double poly(double x,unsigned n){if(n==0){return 1;}if(n==1){poly(x,n
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 08:24:54
大神帮我再改一个,作业,谢谢了// recursive.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"using namespace std;double poly(double x,unsigned n){if(n==0){return 1;}if(n==1){poly(x,n
大神帮我再改一个,作业,谢谢了
// recursive.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
double poly(double x,unsigned n)
{
if(n==0)
{
return 1;
}
if(n==1)
{
poly(x,n)=x;
return x;
}
if(n>1)
{
return ((2n-1)*x*poly(x,n-1)-(n-1)*poly(x,n-2))/n;
}
int main(int argc, char* argv[])
{
double x;
unsigned n;
cin>>x>>n;
cout
大神帮我再改一个,作业,谢谢了// recursive.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"using namespace std;double poly(double x,unsigned n){if(n==0){return 1;}if(n==1){poly(x,n
改了你几个地方,第一个函数
#include <iostream>
using namespace std;
double poly(double x,unsigned n)
{
if(n==0)
{
return 1;
}
if(n==1)
{
//x=poly(x,n)
x=poly(x,0);//赋值语句写反了吧,而且原先的递归是死循环,我就改成n=0了
return x;
}
if(n>1)
{
return ((2*n-1)*x*poly(x,n-1)-(n-1)*poly(x,n-2))/n;//这里你的2n.
}
}//你没写
int main(int argc, char* argv[])
{
double x;
unsigned n;
cin>>x>>n;
cout<<poly(x,n)<<endl;
return 0;
}