2406:c language Exercises to find n-order de polynomial

Source: Internet
Author: User

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.


Values of N and X.


The value of the PN (x).

Sample Input
2 2
Sample Output

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;


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.