Advertisement
NuquernaNarsil

Fibonacci_ciag_iteracja

Sep 24th, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. /* Natomiast wyznaczanie dowolnego wyrazu ciągu Fibonacciego w sposób iteracyjny zaimplementować można następująco:int fib(int n)
  2. */
  3. #include <iostream>
  4. #include <conio.h>
  5. using namespace std;
  6.  
  7. int n;
  8. int fib(int n)
  9. {
  10.  
  11.      int a, b;
  12.      if(n == 0) return 0;
  13.      a = 0; b = 1;
  14.      for(int i=0; i<(n-1); i++)
  15.     {
  16.          b += a;
  17.          a = b-a;
  18.      }
  19.      return b;
  20. }
  21. main ()
  22. {
  23.     cout << "Podaj liczbe z ciagu Fibonacciego ktora cie interesuje: ";
  24.     cin >> n;
  25.     cout << fib(n);
  26.    
  27. getch();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement