HORNER(霍纳)法则的C实现以及算法比较 2.10
来源:互联网 发布:linux删除多个文件命令 编辑:程序博客网 时间:2024/05/16 10:58
这个是2.10题的答案
double algorithm4_horner(double X,int N){double Poly = 0;for(int i = N; i> = 0; i--){聚=聚* X + 1;// printf(“every temp:%f \ n”,temp);}返回聚}
代码很长,可以直接去看结果
请输入X:2.0,
请输入N:9999
,time2为0.024000秒
,time3为0.012000秒
,time4 为0.000000秒
请输入N:99999
,time2为0.412000秒
,time3为0.190000秒
,time4为0.040000秒
请输入N:999999
时间2为4.947000秒
,time3 为2.774000秒,time4为0.346000秒
,
请输入N:5211314
,time2为29.883000秒
,time3为17.617000秒
,time4为1.811000秒
请输入N:
这是代码
的#include <stdio.h>中的#include <stdlib.h>中的#include <time.h>中的#include <math.h>中双A,B,C,D;double algorithm1_pre(double X,int N){double temp = 1;for(int i = 0; i <N; i ++){温度=温度* X;// printf(“every temp:%f \ n”,temp);}回温}double algorithm1(double X,int N){double temp = 0;for(int i = 0; i <N + 1; i ++){温度+ = algorithm1_pre(X,双(I));// printf(“every temp:%f \ n”,temp);}回温}int IsEven(int N){if(N%2 == 0)return 1;if((N + 1)%2 == 0)return 0;else printf(“error”);}double algorithm2_pre(double X,int N){if(N == 0)return 1;if(IsEven(N))返回algorithm2_pre(X * X,N / 2);否则返回algorithm2_pre(X * X,N / 2)* X;}double algorithm2(double X,int N){double temp2 = 0;for(int i = 0; i <N + 1; i ++){TEMP2 + = algorithm2_pre(X,I);// printf(“every 2 temp:%f \ n”,temp2);}return temp2;}double algorithm3_pre(double X,int N){返回pow(X,N);}double algorithm3(double X,int N){double temp = 0;for(int i = 0; i <N + 1; i ++){温度+ = algorithm3_pre(X,I);// printf(“every temp:%f \ n”,temp);}回温}double algorithm4_horner(double X,int N){double Poly = 0;for(int i = N; i> = 0; i--){聚=聚* X + 1;// printf(“every temp:%f \ n”,temp);}返回聚}double test1(double X,int N){ clock_t开始,完成; 双持续时间= 0.0; 开始=时钟(); / *插入你的代码* / A =算法1(X,N); // printf(“你的结果%f \ n”,algorithm1(X,N)); finish = clock(); duration =(double)(finish-start)/ CLOCKS_PER_SEC; // printf(“%d turn Time is”,i + 1); // printf(“%f seconds \ n”,duration); 返回时间;}double test2(double X,int N){clock_t开始,完成; 双持续时间= 0.0; 开始=时钟(); / *插入你的代码* / // printf(“your result2 \ n%f \ n”,algorithm2(X,N)); B =算法2(X,N); finish = clock(); duration =(double)(finish-start)/ CLOCKS_PER_SEC; // printf(“%d turn Time is”,i + 1); // printf(“%f seconds \ n”,duration); 返回时间;}double test3(double X,int N){ clock_t开始,完成; 双持续时间= 0.0; 开始=时钟(); / *插入你的代码* / C = algorithm3(X,N); // printf(“你的结果%f \ n”,algorithm1(X,N)); finish = clock(); duration =(double)(finish-start)/ CLOCKS_PER_SEC; // printf(“%d turn Time is”,i + 1); // printf(“%f seconds \ n”,duration); 返回时间;}double test4(double X,int N){ clock_t开始,完成; 双持续时间= 0.0; 开始=时钟(); / *插入你的代码* / D = algorithm4_horner(X,N); // printf(“你的结果%f \ n”,algorithm1(X,N)); finish = clock(); duration =(double)(finish-start)/ CLOCKS_PER_SEC; // printf(“%d turn Time is”,i + 1); // printf(“%f seconds \ n”,duration); 返回时间;}void main(){双X;int N;printf(“请输入X:”);的scanf( “%LF”,&X);printf(“请输入N:”);的scanf( “%d个”,&N);// printf(“time is%f seconds \ n”,test1(X,N));// printf(“A sum is:%f \ n”,A);printf(“time2为%f seconds \ n”,test2(X,N));// printf(“B sum is:%f \ n”,B);printf(“time3为%f seconds \ n”,test3(X,N));// printf(“C sum is:%f \ n”,C);printf(“time4为%f seconds \ n”,test4(X,N));// printf(“D sum is:%f \ n”,D);系统( “暂停”);}
用到HORNER法则,把百度百科,搬过来展示下基本https://baike.baidu.com/item/%E9%9C%8D%E7%BA%B3%E6%B3%95%E5%88%99 / 4822190?FR =阿拉丁
阅读全文
0 0
- HORNER(霍纳)法则的C实现以及算法比较 2.10
- Horner法则的递归实现
- Horner法则(秦九韶算法 )的程序实现
- Weiss-(DSAA - in C,2.10)Horner法则求多项式
- Horner法则
- Horner法则
- Horner法则
- Horner法则
- 霍纳法则(Horner)/秦九韶算法
- 多项式求值的Horner算法
- Horner规则的递归实现
- 霍纳法则(horner)
- 霍纳(Horner)规则的两种实现方法
- Horner规则实现多项式求值--C语言版
- 字符串比较算法总结以及朴素字符串比较的实现
- 各大排序算法的Objective-C实现以及图形化演示比较
- horner法则求字符串散列值
- Horner Rule(霍纳法则)
- 小学生到底要不要学奥数 学奥数的利弊分析!
- Win2008 r2+oracle rac 11.2.01+starwind 安装手册
- Asteroids!(bfs)
- stringcharbyteslength
- 【BZOJ4034】树上操作(HAOI2015)-树链剖分
- HORNER(霍纳)法则的C实现以及算法比较 2.10
- ViewGroup事件分发
- java编译中可能遇到的问题
- Ubuntu Server 16.04 安装tomcat8
- Tair java c++客户端配置使用
- Juery新增节点之后事件绑定无效
- get_brand_wcpay_request:fail,微信公众号支付的那点坑
- Adobe Acrobat Pro 2017 避免更新
- 将自定义消息发给所有顶层窗口(MFC)