Repo init

pierwsza działająca wersja programu
This commit is contained in:
2024-10-09 20:34:57 +02:00
commit 18ebbc0a2c

80
horner_simple.cpp Normal file
View File

@@ -0,0 +1,80 @@
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
int stopien = 0;
float x = 0;
string str;
vector<string> 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<float> a(stopien);
vector<float> 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;
}