The title computing required to achieve the following function P (n, x), which function is defined as follows:
Function interface definition:
Double P (n-int, Double X);
Wherein n is a nonnegative integer incoming user, x is a double precision floating point. P function returns the corresponding value P (n, x) function. Title ensure that the input and output are in double precision.
Referee test sample program:
#include <stdio.h>
double P( int n, double x );
int main()
{
int n;
double x;
scanf("%d %lf", &n, &x);
printf("%.2f\n", P(n,x));
return 0;
}
/ * Your code will be embedded here * /
Sample input:
10 1.7
Sample output:
3.05
double P( int n, double x )
{
if (n == 0)
return 1;
else if (n == 1)
return x;
else
return ((2 * n - 1) * P(n - 1, x) - (n - 1) * P(n - 2, x)) / n;
}