作业帮 > 综合 > 作业

大神帮我再改一个,作业,谢谢了

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/01 03:06:01
大神帮我再改一个,作业,谢谢了
// 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
改了你几个地方,第一个函数
#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;
}