Facebook
From RKK, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 99
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void Czytaj(vector<float> &A)
  7. {
  8.     int n;
  9.     cout << "Stopien wielomianu: ";
  10.     cin >> n;
  11.     A.resize(n+1);
  12.    
  13.     for(int i = n; i >= 0; i--)
  14.     {
  15.         cout << "a" << i << " = ";
  16.         cin >> A[i];
  17.     }
  18. }
  19.  
  20. float W(vector<float> A, float x)
  21. {
  22.     int n = A.size() - 1;
  23.     float y = A[n];
  24.     for(int i = n-1;i>=0; i--)
  25.     {
  26.         y = x*y + A[i];
  27.     }
  28.     return y;
  29. }
  30.  
  31. int main()
  32. {
  33.     vector<float> A;
  34.     float x;
  35.     Czytaj(A);
  36.     cout << "x = ";
  37.     cin >> x;
  38.     cout << "W(" << x << ") = " << W(A,x);
  39.     return 0;
  40. }
  41.