Home > Back-end >  Who can you help me with my this question? Novice online, really not, thank you
Who can you help me with my this question? Novice online, really not, thank you

Time:10-06

2. Write the algorithm to calculate in a given each coefficient polynomials and the value of the variable x fn (x) the value of the required time as little as possible, (difficulty level 2-3 *)
(hint: each coefficient can be stored in A of the array;
In addition, multiplication of time is the several times of addition operation time)
Fn (x)=anxn + the an - 1 xn xn - an - 1-1 + 2 +... . A2x2 + a1x, a0

CodePudding user response:

I am copying "fun" elsewhere with a problem of answer:


A0 + a1 * x ^ 1. + a2 * x ^ 2 +... + an * x ^ n
The fastest algorithm is:
A0 (a1 + x + x * * * (a2 + x (... + x * (an)))))))

Write function is:
Float poly real (float a [], int n, float x) {
Float result=0;
For (int v=n; V>=0; V -)
Result=a [v] + x * result;
return result;
}

Int main () {
Float a [100]={1, 2, 3};//for coefficient of ai, said 1 + 2 + 3 * * x x x x
Int n=2;//polynomial highest item is square project
Float x=3;
Float ans=poly real (a, n, x);
Printf (" % f ", ans);
return 0;
};
  • Related