Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<cmath>
- 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);
- srand(time(NULL));
- cout << "Podaj rozmiar tablicy" << endl;
- cin >> size;
- double arr[size];
- for (int i = 0; i < size; i++) {
- arr[i] = (float) rand() / RAND_MAX;
- }
- wprost(arr, size, x);
- horner(arr, size, x);
- return 0;
- }
- double wprost(double arr[], int size, double x) {
- double y = 0;
- int a = 0;
- int m = 0;
- for (int i = 0; i < size; i++) {
- y += arr[i] * pow(x, i);
- a++;
- m++;
- }
- cout << "Wprost - Liczba dodawan: " << a << endl;
- cout << "Wprost - Liczba mnozen: " << m << endl;
- return y;
- }
- double horner(double arr[], int size, double x) {
- double y = 0;
- int a = 0;
- int m = 0;
- for (int i = size; i >= 0; i--) {
- y = arr[i] + y * x;
- a++;
- m++;
- }
- cout << "Horner - Liczba dodawan: " << a << endl;
- cout << "Horner - Liczba mnozen: " << m << endl;
- return y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement