Home > Back-end >  The PTA
The PTA

Time:12-06

Subject demanding a function, calculation for n order, coefficient for a [0]... A [n] the polynomial of f (x)=? I=0? N?? X x (a [I]? I?? ) in the value of the x

The original code: (time)
# include & lt; Stdio. H>

# define MAXN 10

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

Int main ()
{
Int n, I;
Double a [MAXN], x;

The scanf (" % d % lf ", & amp; N, & amp; X);
For (I=0; i<=n; I++)
Lf the scanf (" % ", & amp; A [I]);
Printf (" % 1 f \ n ", f (n, a, x));
return 0;
}

/* * your code will be embedded in here/
Double f (int n, double [], a double x)
{
int i,j;
Double sum, k;
sum=0;
K=x;
for(i=0; i<=n; I++)
{
If (i> 1)
{
for(j=1; JK *=x;
}
Else if (I==0) k=1;
Else if (I==1) k=x;
The sum +=a [I] * k;
}
return sum;
}

After the correction:

# include & lt; Stdio. H>

# define MAXN 10

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

Int main ()
{
Int n, I;
Double a [MAXN], x;

The scanf (" % d % lf ", & amp; N, & amp; X);
For (I=0; i<=n; I++)
Lf the scanf (" % ", & amp; A [I]);
Printf (" % 1 f \ n ", f (n, a, x));
return 0;
}

/* * your code will be embedded in here/
Double f (int n, double [], a double x)
{
int i;
Double sum, k;
k=1;
Sum=a, [0].
for(i=1; i<=n; I++)
{
K *=x;
The sum +=a [I] * k;
}
return sum;
}
  • Related