In c + + program design, solve the polynomial function: P (x)=a0x ^ n + a1x ^ (n - 1) +... X + + a (n - 1) an thank you all for the
CodePudding user response:
A0 first into an stored in an array, in a cycle, for various values in the loop with pow, accumulation and want to be in circulation and the accumulative value of p (x)
CodePudding user response:
#include
using namespace std; Int main () { int n; Float c [20]; cout <"Both Please Input n (1 & lt;=n<20) : "; Cin & gt;> n; If (n>=20) return 1; cout <"Both Please coef \ n"; For (int I=0; i<=n; Cin i++) & gt;> C [I]; Float x; cout <"Both Please input x:"; Cin & gt;> x; for (int i=0; i cout }; cout Float result=0; for (int i=0; i<=n; I++) Result=result * x + c [I]; cout return 0; } Results: Both Please Input n (1 & lt;=n<20) : 3 Both Please coef 1.1 2.2 3.3 4.4 Both Please input x: 2.5 1.1 x2.5 ^ 3 + 2.2 x2.5 ^ 2 + 3.3 x2.5 ^ 1 + 4.4=43.5875 CodePudding user response:
refer to 1st floor @ __Chao -l response: a0 first into an stored in an array, in a cycle, for various values in the loop with pow, and want to be in circulation for accumulation, and finally to the accumulative value of p (x) of Thank you very much! ???? CodePudding user response:
Fun reference 2 floor response: # include & lt; Iostream> using namespace std; Int main () { int n; Float c [20]; cout <"Both Please Input n (1 & lt;=n<20) : "; Cin & gt;> n; If (n>=20) return 1; cout <"Both Please coef \ n"; For (int I=0; i<=n; Cin i++) & gt;> C [I]; Float x; cout <"Both Please input x:"; Cin & gt;> x; for (int i=0; i cout }; cout Float result=0; for (int i=0; i<=n; I++) Result=result * x + c [I]; cout return 0; } Results: Both Please Input n (1 & lt;=n<20) : 3 Both Please coef 1.1 2.2 3.3 4.4 Both Please input x: 2.5 1.1 x2.5 ^ 3 + 2.2 x2.5 ^ 2 + 3.3 x2.5 ^ 1 + 4.4=43.5875 Thank you very much! ???? CodePudding user response:
for (int i=0; i<=n; I++) Result=result * x + c [I]; Do you want to read this, the efficiency is much higher than pow, Don't again and again for x I power, But the formula change into The an (an 1 + x + x * * (the an - (2) + x * (an - 3 +... * x (a0)))))) This transformation is the result of the computation the smallest CodePudding user response:
Fun reference 5 floor response: for (int I=0; i<=n; I++) Result=result * x + c [I]; Do you want to read this, the efficiency is much higher than pow, Don't again and again for x I power, But the formula change into The an (an 1 + x + x * * (the an - (2) + x * (an - 3 +... * x (a0)))))) This transformation is the result of the computation of the smallest In fact just a little confused at first, for a while as if to understand a bit, the value of the result after the first cycle should be c [0] I am a freshman, to begin to learn c + + feel good difficult?????? CodePudding user response:
Fun reference 5 floor response: for (int I=0; i<=n; I++) Result=result * x + c [I]; Do you want to read this, the efficiency is much higher than pow, Don't again and again for x I power, But the formula change into The an (an 1 + x + x * * (the an - (2) + x * (an - 3 +... * x (a0)))))) This transformation is the result of the computation of the smallest Another question is why n is less than 20? CodePudding user response:
Because only define the 20th c array Potential worry: too big operation will overflow CodePudding user response:
refer to 6th floor weixin_46285561 response: Quote: refer to fifth floor fun response: for (int I=0; i<=n; I++) Result=result * x + c [I]; Do you want to read this, the efficiency is much higher than pow, Don't again and again for x I power, But the formula change into The an (an 1 + x + x * * (the an - (2) + x * (an - 3 +... * x (a0)))))) This transformation is the result of the computation of the smallest In fact just a little confused at first, for a while as if to understand a bit, the value of the result after the first cycle should be c [0] My freshman year, to begin to learn c + + feel good difficult??????? After the second cycle it should be a [0] * x + [1], and so on!!!!! Wow!!!!! Badly ill?????? Thank you very much! Thank you very much! CodePudding user response:
references to make fun of the eighth floor response: because only define the 20th c array Potential worry: too big operation will overflow Good????