Sunday, 26 February 2012

Factorial of number using Recursive Function


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

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

No comments:

Post a Comment