Advertisement
CosminVarlan

Untitled

Nov 5th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int fib(int n)
  7. {
  8.     if (n==0) return 0;
  9.     if (n==1) return 1;
  10.  
  11.     int a=0;
  12.     int b=1;
  13.     int c;
  14.     for(int i=2; i<=n; i++)
  15.     {
  16.         c = a+b;
  17.         a=b;
  18.         b=c;
  19.     }
  20.     return c;
  21. }
  22.  
  23.  
  24. int main()
  25. {
  26.  
  27.  
  28.     cout <<fib(7)<< endl;
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement