6 2 多項式求值 15分

2021-10-02 02:31:31 字數 736 閱讀 5313

本題要求實現乙個函式,計算階數為n,係數為a[0] … a[n]的多項式f(x)=∑

​i=0

​n​​ (a[i]×x

​i​​ ) 在x點的值。

函式介面定義:

doublef(

int n,

double a,

double x )

;

其中n是多項式的階數,a中儲存係數,x是給定點。函式須返回多項式f(x)的值。

裁判測試程式樣例:

#include

#define maxn 10

doublef(

int n,

double a,

double x )

;int

main()

/* 你的**將被嵌在這裡 */

我的**

#include

doublef(

int n,

double a,

double x )

return sum;

}

別人的

double f (

int n,

double a,

double x )

return sum;

}

我這個通過了 但是算pow容易超時 還是做迴圈累乘比較好

6 2 多項式求值(15分)

採用遞迴的方式解決 答案如下 double f int n,double a,double x 題目如下 本題要求實現乙個函式,計算階數為n,係數為a 0 a n 的多項式f x i 0 n a i x i 在x點的值。函式介面定義 double f int n,double a,double x ...

6 2 多項式求值 15分

本題要求實現乙個函式,計算階數為n,係數為a 0 a n 的多項式 的值。函式介面定義 doublef int n,double a,double x 其中n是多項式的階數,a中儲存係數,x是給定點。函式須返回多項式f x 的值。裁判測試程式樣例 include define maxn 10 dou...

PTA 6 2 多項式求值 (15 分)

本題要求實現乙個函式,計算階數為n,係數為a 0 a n 的多項式f x i 0 n a i x i 在x點的值。double f int n,double a,double x 其中n是多項式的階數,a中儲存係數,x是給定點。函式須返回多項式f x 的值。include define maxn 1...