longer?
//Recursive function that calculates factorial.
long factorial
{
long n;
long fact;<p> cout<<"Please enter a positive number."<<endl;
cin>>n;
if(n>1) //this statement to make sure the number is positive
{
fact=n * factorial(n -1); //formula for the factorial, recursion
}
else //If n=1, recursion stops and flow of logic
{
fact=1
}
return(fact);//Return fact to the next level of recursion
}
*edit: Please use code tags in the future, thanks!
This post has been edited by Martyr2: 11 February 2008 - 10:34 AM

New Topic/Question
Reply



MultiQuote








|