霍纳规则解决多项式的求值问题

霍纳规则用来简化朴素多项式的求值。它将一元n次多项式的求值问题转化为n个一次式。

霍纳规则是采用最少的乘法运算策略,求多项式A(x) = anxn+ an-1xn-1+...+ a1x + a0在x0处的值,该规则是A(x0)=(...((anx0+ an-1)x0+...+ a1)x0+ a0)

 1 #include<stdio.h>
 2 
 3 int horner(int a[], int x, int n);
 4  
 5 int main()
 6 {
 7     int n;
 8     scanf("%d", &n);
 9     
10     int a[n + 1];
11     int x;
12     for(int i = 0; i <= n; i++){
13         scanf("%d", &a[i]);
14     }
15     
16     scanf("%d", &x);
17     printf("%d", horner(a, x, n));
18     
19     return 0;
20 } 
21 
22 int horner(int a[], int x, int n)
23 {
24     int i = n;
25     int result = x;
26     while(i > 0){
27         result = a[i] + result * x;
28         i--;
29     }
30     
31     return result;
32 }

 

转载于:https://www.cnblogs.com/legoxz/p/8525134.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值