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