zoukankan      html  css  js  c++  java
  • Horner's rule (霍纳法则)

    #include <iostream>
    using namespace std;

    double hornerExp(double a[], int n, double x);

    int main()
    {
        
    int n;
        
    double *a;
        
    double x;

        cout
    <<"Input the n (a0, a1, , an):\n";
        cin
    >>n;

        a 
    = new double[n+1];
        cout
    <<"Input a0, a1, , an\n";
        
    for (int i = 0; i <= n; i++) {
            cin
    >>a[i];
        }

        cout
    <<"Input the x"<<endl;
        cin
    >>x;

        cout
    <<"y = "<<hornerExp(a, n, x)<<endl;

        delete []a;

        
    return 0;
    }


    double hornerExp(double a[], int n, double x)
    {
        
    double y = 0.0;

        
    for (int i = n; i >= 1--i) {
            y 
    += a[i];
            y 
    *= x;
        }
        y 
    += a[0];

        
    return y;
    }
  • 相关阅读:
    ssh免密登录
    jdk安装
    jq选择器
    使用<button></button>标签
    mysql连接字符串
    如何把maven项目转成web项目
    pl/sql连接远程oracle
    Oracle 存储过程
    SQL Server存储过程
    MySQL存储过程
  • 原文地址:https://www.cnblogs.com/Henrya2/p/1430545.html
Copyright © 2011-2022 走看看