What is the issue?
Hey @Nidhi_Alipuria
your answer is overflowing
Here I updated it
#include<iostream>
using namespace std;
long long calculate(int n,long long dp[])
{
if(n==0)
return 1;
if(n==1)
return 2;
if(dp[n]!=0)
return dp[n];
long long a=calculate(n-1,dp);
long long b=calculate(n-2,dp);
//cout<<a<<b<<" ";
return dp[n]=a+b;
}
int main()
{
int test;
cin>>test;
long long dp[100]={0};
while(test–)
{
int n;
cin>>n;
calculate(n,dp);
cout<<dp[n]<<endl;
}
}
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.