Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- long long fibo_iteracyjnie (int n)
- {
- unsigned long long x0 = 0;
- unsigned long long x1 = 1;
- for (int i = 0; i < n; ++i)
- {
- long temp = x0 + x1;
- x0 = x1;
- x1 = temp;
- }
- return x0;
- }
- long long fibo_rekurencyjnie(int n)
- {
- if (n <= 1) return n;
- else return fibo_rekurencyjnie(n - 2) + fibo_rekurencyjnie(n - 1);
- }
- int main() {
- int n = 50;
- unsigned long long x1, x2;
- clock_t start, end;
- double czas_obl;
- start = clock(); //zapamietanie aktualnego czasu systemowego
- x1 = fibo_iteracyjnie(n);
- end = clock();
- czas_obl = 1.0 * (end - start) / CLOCKS_PER_SEC; // czas wyznaczany jest w sekundach
- cout << "Iteracyjnie czas obliczen = " << czas_obl << endl;
- cout << "Wynik iteracyjnie:" << x1 << endl;
- system("PAUSE");
- start = clock(); //zapamietanie aktualnego czasu systemowego
- x2 = fibo_rekurencyjnie(n);
- end = clock();
- czas_obl = 1.0 * (end - start) / CLOCKS_PER_SEC; // czas wyznaczany jest w sekundach
- cout << "Rekurencyjnie czas obliczen = " << czas_obl << endl;
- cout << "Wynik rekurencyjnie:" << x2 << endl;
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement