This paper illustrates the realization of n-order polynomial by using recursive method in C + +. Share to everyone for your reference, specific as follows:
*
* Author: Liu Tongbin
* Date of Completion: November 24, 2012
* Version number: v1.0
* Input Description:
* Problem Description: Use the recursive method to find the value of the N-order polynomial.
* Program output:
* Problem Analysis: slightly
* Algorithm design: Slightly * *
#include <iostream>
using namespace std;
int main ()
{
double P (double,double);
Double s,n,x;
cout<< "Please enter the value of N and x:";
cin>>n>>x;
S=p (n,x);
cout<< "The value of the polynomial is:" <<s<<endl;
return 0;
}
Double p (double n,double x)
{
double s; The function name cannot be the same as the variable name.
if (n==0)
{
s=1;
}
else if (n==1)
{
s=x
}
else
{
s= (2*n-1) *x-p ((n-1), X)-(n-1) *p ((n-2), x))/n;//recursion. On-machine instruction is written on s= ((2*n-1) *x*p ((n-1), X)-(n-1) *p ((n-2), x))/n when input 3 4 o'clock, the result is 154
} return
s;
}
I hope this article will help you with C + + program design.