my code is printing the output in the same line in spite of using endl
as you switch to another question everything goes off.
Endl is not working
Hi Aakash
Please hard refresh your page (ctrl + shift + R) it should work fine then, and you can submit a code and later can view that submission.
#include<bits/stdc++.h> using namespace std; int dp(int n) { int dp[n]; dp[0]=0; for(int i=1;i<=n;i++) { if(i<=2) { dp[i]=i; } else { dp[i]=dp[i-1]+(i-1)*dp[i-2]; } } return dp[n]; } int main() { int t; cin>>t; while(t>0) { int n; cin>>n; int ans=dp(n); cout<<ans<<endl; t–; } }
what is wrong with the code?
If you are returning return dp[n]; then initially you should make the array dp of size n+1, because indexing of array always starts from 0 and ends at n-1.
And It’s a request that from next time please copy your code at cb.lk/ide, save it and share that link in your doubt. It will be easier for us to debug your code then and will be able to resolve your doubt faster.
I hope this helps you
#include<bits/stdc++.h> using namespace std; int dp(int n) { int dp[n+1]; dp[0]=0; for(int i=1;i<=n;i++) { if(i<=2) { dp[i]=i; } else { dp[i]=dp[i-1]+(i-1)*dp[i-2]; } } return dp[n]; } int main() { int t; cin>>t; while(t>0) { int n; cin>>n; int ans=dp(n); cout<<ans<<endl; t–; } }
still not working .the code is in the above link
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.