#include
using namespace std;
int fact(int n){
if(n==0){
return 1;
}
int ans;
ans=n*fact(n-1);
return ans;
}
int main(){
int n;
cin>>n;
cout<<fact(n);
}
i have done it using recursion…why it is showing error?
Broken calculator
Hey @tishya_goyal
For calculating factorial of large numbers, you need to use dynamic programming approach, using recursion will involove repeated calculations(and hence more time complexity) and more space also, so you need to optimize your approach using DP.
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.
1 Like