" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
#include <iostream>
using namespace std;
int horner(int wspol[], int stop, int x)
{
if(stop == 0)
{
return wspol[0];
}
return x * horner(wspol, stop - 1, x) + wspol[stop];
}
int main()
{
int *wspol; // tablica wspolczynnikow
int stop, a; // stopien wielomianu i jego argument
cout << "Podaj stopien wielomianu: ";
cin >> stop;
cout << endl;
wspol = new int [stop + 1];
for(int i = 0; i <= stop; i++)
{
cout << "Podaj wspolczynnik przy potedze " << stop - i << ": ";
cin >> wspol[i];
cout << endl;
}
cout << "Podaj a: ";
cin >> a;
cout << endl;
cout << "W( " << a << " ) = " << horner(wspol, stop, a) << endl;
delete [] wspol;
return 0;
}