Advertisement
polpoteu

AiSD Horner final?

Nov 13th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <iomanip>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. int main(int argc, char** argv)
  8. {
  9.     clock_t start, stop;
  10.     double czas;
  11.     cout<<"Podaj wielkosc tablicy : ";
  12.     int n;
  13.     cin>>n;
  14.     srand(time(0));
  15.     double x=0.1;
  16.     int *a;
  17.     a = new int [n];
  18.     int v=0;
  19.     start=clock();
  20.     for (int i=0; i>n; i++){
  21.         a[i]=rand()/double(RAND_MAX);
  22.     }
  23.     for (int i=n; i>=0; i--){
  24.         v=+a[i]+v*x;
  25.  
  26.     }
  27.     stop=clock();
  28.     czas = double(stop-start)/CLOCKS_PER_SEC;
  29.  
  30.     cout<<"Wynik to = "<< v <<endl<<"czas to= "<< std::setprecision(20)<<czas<<endl;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement