基本数值计算秦九韶算法

来源:互联网 发布:windows hello 编辑:程序博客网 时间:2024/06/06 05:04

#include "stdafx.h"

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>

using namespace std;

int main()
{
 float res, a[7] = {3, 12, 8, -3.5, 7.2, 5, -13}, x = 6;
 res = 3.0;
    for (int i = 0; i < 6; i++) {
        res = res * x + a[i + 1];
    }
    cout << setiosflags(ios::fixed) << setprecision(3) << res << endl;
    system ("pause");
    return 0;
}