Sunday, 18 March 2012

Factorial Of Number using Recursion


# include <iostream>
using namespace std;
int factorial(int n);
int main()
{
for(int i=1; i<=10; i++)
cout<<i<<"!= "<<factorial(i);
cout<<endl;


return 0;
}


int factorial(int n)
{
if (n==1)
return 1;
else
return n*factorial(n-1);
}

No comments:

Post a Comment