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

CodePudding user response:

Fun
reference 4 floor 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

Once I thought see code can read about. But now, alas.
Can you help me on the first line and the bottom third
Thank you

CodePudding user response:

Fun
reference 4 floor 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

Who can you help me have a look at this question?

Known input sequence of each element in the value of at least two elements, design algorithm to find the elements in the sequence of all of the biggest rise, fall subsequence, for example, if the elements in the order (1,20,30,12,3,5,7,4,6,100,11,8), the output as (1), 30, 30,12,3 (), (3, 5, 7), (7, 4), (4,6,100),,11,8 (100),

CodePudding user response:

This seems a cycle can solve

Record the current start from there, ascending or descending order status
And see the next point, whether to still can continue to maintain the state (ascending or descending), if you can, continue to the next point to judge
Can't, I put together from the beginning to the current output, and then starting current, to change the status to fall or rise to continue on to the next point

CodePudding user response:


Int main () {
Int ary []={1, 20, 30, 12, 3, 5, 7, 4, 6, 100, 11 and 8,};
Int nLen=sizeof (ary)/sizeof (ary [0]).
Int bAsce=ary [1] & gt; Ary [0]? 1:0;
Int nStart=0; Int x, y;
For (x=1; xIf (bAsce) {
If (ary [x] & gt; Ary] [x - 1) continue;
BAsce=0;
} else {
If (ary [x] <=ary] [x - 1) continue;
BAsce=1;
}
Printf (" {");
For (y=nStart; YPrintf (" % d ", ary [y]);
}
Printf ("} \ n ");
NStart=x - 1;
}
Printf (" {");
For (y=nStart; YPrintf (" % d ", ary [y]);
}
Printf ("} \ n ");

return 0;
}
  • Related