Write the recursion function to print the factoial of a number
And also give its working(dry run):)
![]() |
Write the recursion function to print the factoial of a number
And also give its working(dry run):)
although its your assignment but I will make it for you!
#include<iostream>
using namespace std;
int fact(int,int);
int main()
{
int ans ;
int a ;
cout << "Enter a number: "
cin >> a ;
ans = fact(a , 1);
cout << ans ;
return 0 ;
}
int fact(int b, int ans)
{
if(b == 0)
return 1 ;
else if(b == 1)
return ans ;
else
ans *= b;
return fact(b - 1, ans);
}
vote for my answer...
All times are GMT -7. The time now is 04:36 AM. |