Thursday, 24 January 2013

recursive factorial

#include <iostream>

using namespace std;
int factorial(int);
int main()
{
    int number=5;
 int fact;
 fact = factorial(number);
 cout << fact;


    cin.get();
    return 0;
}

int factorial(int number)
{
    if(number<=1)
    {

        return 1;
    }

    else

    return number+factorial(number-1);
}

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Enterprise Project Management