4-2 Polynomial evaluation

Source: Internet
Author: User

The subject requires the implementation of a function to calculate the order ofn, the coefficient isa[0]...a[n]The polynomialF (x) =∑ni=0 (A[I]*XI) f (x) x The value at the point.

function Interface Definition:
double f( int n, double a[], double x );

Which n is the order of the polynomial, the a[] storage factor, x is the given point. The function must return f(x) the value of the polynomial.

Example of a referee test procedure:
#include <stdio.h>#define MAXN 10double f( int n, double a[], double x );int main(){    int n, i;    double a[MAXN], x;    scanf("%d %lf", &n, &x);    for ( i=0; i<=n; i++ )        scanf(“%lf”, &a[i]);    printf("%.1f\n", f(n, a, x));    return 0;}/* 你的代码将被嵌在这里 */
Input Sample:
2 1.11 2.5 -38.7
Sample output:
-43.1

程序代码:*

Double f (int n, double a[], double x)
{

Double sum;
if (n>=0)
Sum=a[n]*pow (x,n) +f (n-1,a,x);
return sum;
}

4-2 Polynomial evaluation

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.