Polynomial evaluation

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_43912065/article/details/102731897

This problem required to achieve a function to calculate the number of order n, coefficients a [0] ... a [n ] is the polynomial F (X) = [Sigma
I = 0
n-
(A [I] X ×
I
) values at x.

Function interface definition:
Double F (int n, Double A [], Double X);
where n is the order of the polynomial, a [] is stored in the coefficient, x is a given point. Shall return polynomial function f (x) of.

Referee test sample program:
#include <stdio.h>

#define MAXN 10

double 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;

}

/ * Your code here will be embedded * /
Input Sample:
1.1 2
1 2.5 -38.7
Output Sample:
-43.1

double f(int n,double a[],double x)
{
double sum=0,mul=1;
for(int i=0;i<=n;i++)
{
sum+=a[i]mul;
mul
=x;
}
return sum;
}

Guess you like

Origin blog.csdn.net/weixin_43912065/article/details/102731897