Advertisement
rootuss

horner

Jan 2nd, 2017
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void wpisz(double T[], int n)
  6. {
  7.     cout << "podaj wspolczynniki wielomianu: " << endl;
  8.  
  9.     for (int i=0;i<=n;i++)
  10.     {
  11.         cout<<"podaj wspolczynnik "<<i<<": ";
  12.         cin>>T[i];
  13.     }
  14.     cout<<endl;
  15. }
  16.  
  17. double oblicz(double A[],int n, double x )
  18. {
  19.     double w=A[0];
  20.     for(int i=1;i<=n;i++)
  21.     {
  22.         w=w*x+A[i];
  23.     }
  24.     return w;
  25. }
  26.  
  27. double obliczrek(double A[],int n, double x )
  28. {
  29.     if(n==0)
  30.     {
  31.         return A[0];
  32.     }
  33.  
  34.     else
  35.     {
  36.         return obliczrek(A, n-1,x)*x +A[n];
  37.     }
  38. }
  39.  
  40.  
  41. int main()
  42. {
  43.     int  n;
  44.     cout << "Podja stopien wielominau: ";
  45.     cout<<endl;
  46.     cin>>n;
  47.     cout<<endl;
  48.  
  49.     double Tab[n+1];
  50.     wpisz(Tab,n);
  51.  
  52.     double x;
  53.     cout<<"podaj argument x: ";
  54.     cin>>x;
  55.  
  56.     cout<<endl;
  57.     cout<<"Wynik to: "<<obliczrek(Tab,n,x)<<endl;
  58.  
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement