#include #include #include using namespace std; int main() { int stopien = 0; float x = 0; string str; vector temp; cout << "Program do obliczenia wielomianu schemat hornera\n"; fstream file("dane.txt"); if (!file) { cerr << "Nie udalo sie otworzyc plik\n"; return -2; } while (getline(file, str)) { temp.push_back(str); stopien++; } file.close(); if (stopien <= 0) { cout << "Podano niepoprawny stopien!"; return -1; } // cout << "stopien = " << stopien << endl; vector a(stopien); vector b(stopien); for (int i = stopien - 1, j = 0; i >= 0; i--, j++) { a[i] = stof(temp[j]); // cout << "temp[" << i << "]=" << temp[j] << endl; } // for (int i = 0; i < a.size(); i++) // { // cout << "a[" << i << "]=" << a[i] << endl; // } cout << "Podaj x dla ktorego szukamy rozwiazania: "; cin >> x; for (int i = stopien - 1; i >= 0; i--) { if (i == stopien) { b[i] = a[i]; } else if (i > 0) { b[i] = a[i] + b[i + 1] * x; } else if (i == 0) { b[i] = a[i] + b[i + 1] * x; } // cout << i << endl; } for (int i = 0; i < b.size(); i++) { cout << "b" << i << ": " << b[i] << "\n"; } cout << "Rozwiazaniem wielomianu jest: " << b[0] << endl; return 0; }