Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- #include <ctime>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- double horner(double a[], int n, int x){
- double v =0;
- for(int i =n; i>=0;i--){
- v = a[i]+v*(double)x;
- }
- return v;
- }
- double horner_recznie(double a[], int n, int x){
- double wynik =0;
- unsigned t0 = clock();
- for(int i =n; i>=0; i--){
- wynik = wynik + a[i]*pow(x,i);
- }
- unsigned czas = clock()-t0;
- return wynik;
- }
- int main()
- {
- srand (time(NULL));
- cout<<"Podaj rozmiar tablicy :";
- int r;
- cin>>r;
- double a[r];
- for(int c =0; c<11; c++){
- for(int i =0; i<r; i++){
- double random = (double)rand() /(double)RAND_MAX;
- a[i] = random;
- }
- int x = rand()%r;
- cout.precision(25);
- clock_t p;
- double czas;
- p = clock();
- double h1 = horner(a, r-1, x);
- p = clock() - p;
- czas = ((double)p)/CLOCKS_PER_SEC;
- cout<<"czas: "<<czas<<endl;
- double h2 = horner_recznie(a, r-1, x);
- cout<<"horner wynik :"<<h1<<endl;
- cout<<"horner recznie wynik : "<<h2<<endl;
- /* if(h1-h2 != 0) cout<<"rozne"<<endl;
- cout<<endl;*/
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement