I. GOT TLE AGAIN

I got T.L.E again

The code :

#include
using namespace std;
#define mod 1000000007

int fib (int n){
if ((n==0)||(n==1)){
return 1;
}
int a= fib(n-1);
int b= fib(n-2);
return(a+b);
}
int main(){
int t;
cin>>t;
while(t–){
int n;
cin>>n;
cout<<fib(n+1)<<endl;
}
}

hello @kartiksinghal0611

yeah because of same reason.

use loop to generate nth fibonnaci.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.