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 = 0;
- while (j < 10) {
- for (int i = 0; i < size; i++) {
- arr[i] = (float) rand() / RAND_MAX;
- }
- cout << "Krok " << j + 1 << ": " << endl;
- wprost(arr, size, x);
- horner(arr, size, x);
- cout << endl;
- 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 << "Wprost - Wynik to: " << y << endl;
- cout << "Wprost - 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 << "Horner - Wynik to: " << y << endl;
- cout << "Horner - 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