码迷,mamicode.com
首页 > 其他好文 > 详细

第一章 基本概念_利用霍纳规则求多项式的值(递归)

时间:2016-09-30 21:03:37      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

#include <stdio.h>  
#include <stdlib.h>  
#define LEN 3  
int hornor(int [],int,int);  
int main()  
{  
   int a[3]={1,2,3};//数组表示多项式的系数  
   int x=2;//多项式的自变量值  
   int result=0;//存放结果  
   result = hornor(a,0,2);  //3*2^2+2*2^2+1*2^0
                             //    (3*2+2)*2+1
   printf("%d\n",result);  
   exit(0);  
}  
 
 int hornor(int list[],int n,int x)  
 //利用递归实现霍纳规则  
{  
     if(n == LEN-1)  
    {  
        return list[LEN-1];//递归出口  
    }  
    else  
    {                                                                                                          
       return hornor(list,n+1,x)*x+list[n];//递归过程  
     }  
 }

第一章 基本概念_利用霍纳规则求多项式的值(递归)

标签:

原文地址:http://www.cnblogs.com/wangminlomt5/p/5924558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!