JakubJaneczek

Zadanie 26

Apr 8th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. int a,b;
  5.  
  6. int fibonacci(int n)
  7. {
  8.     int a=2;
  9.     int c;
  10.     if(n==0)
  11.     {
  12.        return 0;
  13.     }
  14.     if(n==1)
  15.     {
  16.         return 1;
  17.     }
  18.     int c1=0;
  19.     int c2=1;
  20.     while(a<=n)
  21.     {
  22.         c=c1+c2;
  23.         c1=c2;
  24.         c2=c;
  25.         a++;
  26.     }
  27.     return c;
  28. }
  29.  
  30. int main()
  31. {
  32.     cout << "Podaj liczbe"<<endl;
  33.     cin >> a;
  34.     cout << fibonacci(a)<<endl;
  35.     cout << "Liczba 55"<<endl;
  36.     cout << fibonacci(55)<<endl;
  37.     cout << "Liczba 25"<<endl;
  38.     cout << fibonacci(25)<<endl;
  39.     return 0;
  40. }
Add Comment
Please, Sign In to add comment