Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int fib(int n)
- {
- if (n==0) return 0;
- if (n==1) return 1;
- int a=0;
- int b=1;
- int c;
- for(int i=2; i<=n; i++)
- {
- c = a+b;
- a=b;
- b=c;
- }
- return c;
- }
- int main()
- {
- cout <<fib(7)<< endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement