Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- #include<ctime>
- using namespace std;
- double wprost(double arr[], int size, double x);
- double horner(double arr[], int size, double x);
- int main(){
- double x = 3.5;
- int size;
- cout.precision(10);
- cout << "Podaj rozmiar tablicy" << endl;
- cin >> size;
- double arr[size];
- int j = 5;
- while (j > 0) {
- for (int i = 0; i < size; i++) {
- arr[i] = (float) rand() / RAND_MAX;
- }
- wprost(arr, size, x);
- horner(arr, size, x);
- j--;
- }
- return 0;
- }
- double wprost(double arr[], int size, double x) {
- clock_t start = clock();
- double y = 0;
- for (int i = 0; i < size; i++) {
- y += arr[i] * pow(x, i);
- }
- cout << "Wynik to: " << y << endl;
- cout << "Czas potrzebny na wykonanie obliczen to: " << float(clock() - start)/CLOCKS_PER_SEC << endl;
- return y;
- }
- double horner(double arr[], int size, double x) {
- clock_t start = clock();
- double y = 0;
- for (int i = size; i >= 0; i--) {
- y = arr[i] + y * x;
- }
- cout << "Wynik to: " << y << endl;
- cout << "Czas potrzebny na wykonanie obliczen to: " << float(clock() - start)/CLOCKS_PER_SEC << endl;
- return y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement