#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;
double roundNumber(double value) {
return round(value * 1000.0) / 1000.0;
}
double powerAccumMethod(vector<double>& coeffs, double x) {
double total = 0.0;
double power = 1.0;
int n = coeffs.size();
for (int i = n - 1; i >= 0; i--) {
total += coeffs[i] * power;
power *= x;
}
return total;
}
double hornerMethod(vector<double>& coeffs, double x) {
double result = coeffs[0];
for (int i = 1; i < coeffs.size(); i++) {
result = result * x + coeffs[i];
}
return result;
}
int main() {
setlocale(LC_ALL, "ru");
ifstream dataFile("data.txt");
vector<double> coeffs;
double temp;
while (dataFile >> temp) {
coeffs.push_back(temp);
}
dataFile.close();
const double X_START = 0.5;
const double X_END = 2.0;
const double H = 0.25;
for (double x = X_START; x <= X_END + 0.01; x += H) {
double resPow = roundNumber(powerAccumMethod(coeffs, x));
double resHorner = roundNumber(hornerMethod(coeffs, x));
cout << resPow << "\t";
cout << resHorner << endl;
}
return 0;
}
______________________1¶¶¶¶_____________________
_______________________1¶__¶¶¶¶___________________
_______________________¶1___1¶¶¶__________________
_______________________¶1____11¶¶_________________
_______________________¶1_____11¶1________________
___________1111111_____¶1______¶1¶________________
________1¶¶111111¶¶¶¶1_¶1______11¶¶_______________
________¶¶¶111______1¶¶¶1_______¶1¶_______________
_________1¶¶¶¶¶¶¶1_____¶¶_______¶1¶1______________
_____________1¶¶¶¶¶1___1¶_______11¶¶______________
________________¶¶1¶1__1¶_______11¶¶______________
_________________1¶_¶___¶________11¶______________
__________________¶¶1¶__¶________11¶______________
___________________¶_¶1_¶________11¶11111_________
___________________1¶_¶_¶________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶1_
____________________¶1¶¶¶1______¶1111111¶11¶___1¶_
___________________1111111¶¶__1¶111_11¶11¶_¶1___¶1
________________1¶1111111¶1¶¶1¶_¶1_11¶___1¶1¶___¶1
_____________11¶¶_1¶1_____1_¶¶_¶1_1¶¶_____¶_____¶_
___________1¶¶¶¶_¶¶¶1_______¶_¶1_1¶¶1_____¶____¶¶_
__________1¶__¶_¶1__¶¶_____111¶_¶11¶______¶___¶¶__
__________¶1___1¶___¶¶______1__11¶¶______1¶__¶¶___
__________¶____¶____¶1_____1¶__¶¶¶1______¶1_¶1____
_________1¶___¶¶___¶¶_____¶¶__¶1¶¶______1¶_¶1_____
_________¶¶__¶¶___¶¶_____¶¶___1¶¶_______¶¶1¶______
_________¶1_¶¶__1¶1____1¶1___¶1¶_________11_______
________¶¶_¶¶__¶¶____1¶¶___1¶1¶___________________
_______1¶¶¶1_¶¶1____¶¶1___11¶¶____________________
________11__¶¶____1¶¶_____¶¶¶_____________________
___________¶1____¶¶1____¶¶1¶______________________
__________¶1___1¶1____1¶1¶¶_______________________
_________¶1___¶¶____111¶¶1________________________
________¶¶__1¶1___1_1¶¶¶__________________________
________¶1_1¶1____¶¶¶¶1___________________________
_______¶¶__1¶__1¶¶¶¶1_____________________________
____1¶¶1____1¶¶¶¶¶1_______________________________
1¶¶¶¶1__1¶¶¶¶11___________________________________
¶¶¶¶_1¶¶1_________________________________________
1¶1¶¶¶____________________________________________