Home > Back-end > Have bosses can complete help me work out this problem? Thank you for the
Have bosses can complete help me work out this problem? Thank you for the
Time:10-07
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:
Where is the problem like how just seen Double a [n]={a0, a1,... The an}; Double s=x; For (int k=n - 1; K> 0; K -) S=a + [k - 1] a [k] * s Printf (" % lf ", s);
CodePudding user response:
Change Double a [n + 1)={a0, a1,... The an}; Double s=a [n]. For (int k=n - 1; K> 0; K -) S=a [k - 1) + x * s; Printf (" % lf ", s);
CodePudding user response:
Ha ha, I was drunk, he had been around in Double a [n + 1)={a0, a1,... The an}; Double s=x * a [n] + a (n - 1); For (int k=n - 2; K>=0; K -) S=a [k] + x * s; Printf (" % lf ", s);
CodePudding user response:
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; };
This is which school problem, this is the fourth time answered