Horner規則的迭代版本

2021-06-04 13:04:48 字數 908 閱讀 5595

再寫個迭代版本,感覺比遞迴更好

horner規則的迭代版本:

#include /*horner規則使多項式求值所需乘法次數最少

* 對 a(x) = a[n]x^n + a[n-1]x^(n-1) + ... + a[1]x^1 + a[0]x^0

* 有a(x) = (...((a[n]x + a[n-1])x + ... + a[1])x + a[0])

* * 這是個迭代實現:

* coeffi_array: 係數陣列首位址;

* max_index: 係數陣列的最後一項的索引(上式中的 n );

* x: 呵呵,未知數唄. 用具體的數帶入

* * note: 規定在多項式的常數項中(a[0]), 有 0^0 = 1.

* */

int horner_iterative(const int *coeffi_array, int max_index, int x)

return result;

}int main(void)

while (amount <= 0);

int a[amount];

printf("input the cofficients(like:x,y,z or x y z):");

for (i = 0; i < amount; ++i)

printf("input the x:");

scanf("%d", &x);

result = horner_iterative(a, amount - 1, x);

printf("the result is :%d", result);

getch();

return 0;

}

Horner規則求解多項式的值

一.目的與背景知識 1 生成乙個多項式 2 根據horner規則求解多項式的值。偽 如下 y 0 for i n down to 0 y a i x y 上述偽 即描述了求解a 0 a 1 x 1 a n x n 二.實現 1 多項式展示與計算類 include namespace myalgori...

Horner規則實現多項式求值 C語言版

這裡先簡單說一下霍納規則 horner 採用最少的乘法運算策略,求多項式an x n an 1 x n 1 a1 x a0,在x0 處的值。即h x0 an x0 an 1 x0 a1 x0 a0,也就是說盡可能地提取公因數x 0以減少乘法運算次數。下面用c實現這個演算法。horner多項式求解 i...

Android版本迭代

先來說說versioncode和versionname versioncode 1 對消費者不可見,僅用於應用市場 程式內部識別版本,判斷新舊等用途。versionname 1.0 展示給消費者,消費者會通過它認知自己安裝的版本.更新版本修改versioncode的值,必須是int哦 版本公升級ap...