2406:c language exercises for n-order de polynomial time limit:1 Sec Memory limit:128 MB
submit:961 solved:570
[Submit] [Status] [Web Board] Description a recursive method for the value of the N-order polynomial, the recursive formula is n=0 PN (x) =1 n=1 pn (x) =xn>1 pn (x) = ((2n-1) *x* pn-1 (x)-(n-1) * PN-2 (x))/n The result retains 2 decimal places.
Input
Values of N and X.
Output
The value of the PN (x).
Sample Input
2 2
Sample Output
5.50
HINT
The main function is given below, and it is not required to include the following main function when committing
/* C code */
int main ()
{
int x,n;
scanf ("%d%d", &n,&x);
printf ("%.2f\n", Polya (n,x));
return 0;
}
/* C + + code */
int main ()
{
int x,n;
cin>>n>>x;
Cout<<setiosflags (ios::fixed);
Cout<<setprecision (2);
Cout<<polya (n,x) <<endl;
return 0;
#include <stdio.h>float polya (int n,int x) { float sum; if (n==0) sum=1; else if (n==1) sum=x; else if (n>1) sum= ((2*n-1) *x*polya (n-1,x)-(n-1) *polya (n-2,x))/n; return sum;} int main () { int x,n; scanf ("%d%d", &n,&x); printf ("%.2f\n", Polya (n,x)); return 0;}
Note that the data type of the function is called because the last two-bit fractional output is preserved!
2406:c language Exercises to find n-order de polynomial