Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Generating the 'n' th fibonacci number
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- ll ans=0;
- ll fib( ll n )
- {
- if ( n==1 ) return 0;
- if ( n==2 ) return 1;
- ans=fib(n-1); + fib(n-2);
- return ans;
- }
- void solve()
- {
- int n;
- cout<<"Enter the term number : ";
- cin>>n;
- ans=fib(n);
- cout<<"'n'th Fibonacci number is : "<<ans<<"\n";
- }
- int main()
- {
- int t;
- cout<<"Enter number of test cases : ";
- cin>>t;
- while ( t-- ) solve();
- return 0;
- }
Add Comment
Please, Sign In to add comment