Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Natomiast wyznaczanie dowolnego wyrazu ciągu Fibonacciego w sposób iteracyjny zaimplementować można następująco:int fib(int n)
- */
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int n;
- int fib(int n)
- {
- int a, b;
- if(n == 0) return 0;
- a = 0; b = 1;
- for(int i=0; i<(n-1); i++)
- {
- b += a;
- a = b-a;
- }
- return b;
- }
- main ()
- {
- cout << "Podaj liczbe z ciagu Fibonacciego ktora cie interesuje: ";
- cin >> n;
- cout << fib(n);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement