## Trending News

Promoted

# 寫一個程式用Horner's rule來求多項式

Horner's rule is a strategy for evaluating a polynomialA(X)

Write a C program to evaluate a polynomial using Horner's rule

寫一個程式用Horner's rule來求多項式的值

多項式由使用者輸入 用scanf 來讀輸入

麻煩大大解答一下 感謝

### 1 Answer

Rating

- 大豬Lv 41 decade agoFavorite Answer
#include <stdio.h>

#include <stdlib.h>

int main()

{

double a[100], b[100]={0}, x;

int i, n;

printf("請輸入 A(X) 的最高項次 X^n, n= ");

scanf("%d", &n);

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

{

printf("請輸入A(X)的係數 a%d= ",i);

scanf("%lf",&a[i]);

}

printf("請輸入 X= ");

scanf("%lf",&x);

//Horner's rule

b[n]=a[n];

for(i=n-1; i>=0; i--)

b[i]=a[i]+b[i+1]*x;

printf("A(%lf) = %lf\n",x,b[0]);

system("PAUSE");

return 0;

}

Still have questions? Get your answers by asking now.