Log in

View Full Version : Recusion function


prashant kumar
Oct 16, 2008, 07:14 AM
Write the recursion function to print the factoial of a number
And also give its working(dry run):)

mani_jeddah
Oct 16, 2008, 09:59 AM
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...