6-2多项式求值
1 double f(int n,double a[],double x){ 2 if(n<0 || n>MAXN){ 3 return 0.0; 4 } 5 double result=0.0; 6 double power_of_x=1.0; 7 for(int i=0;i<=n;i++){ 8 result +=a[i]*power_of_x; 9 power_of_x*=x; 10 } 11 return result; 12 }
其中
1 result +=a[i]*power_of_x;
和
1 result =result +a[i]*power_of_x;,使用这个,某种情况会出错,优先使用上面那种
浙公网安备 33010602011771号