commit 18ebbc0a2caf2b1520be2d1b08b1638887d87e51 Author: hamx Date: Wed Oct 9 20:34:57 2024 +0200 Repo init pierwsza działająca wersja programu diff --git a/horner_simple.cpp b/horner_simple.cpp new file mode 100644 index 0000000..c54b714 --- /dev/null +++ b/horner_simple.cpp @@ -0,0 +1,80 @@ +#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; +} \ No newline at end of file