C recursive function

I.e., from the recursive function calls the function, in the functions that calls itself directly or indirectly, i.e. nesting function calls is the function itself.   

E.g:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

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

int main()
{
    int n = 6;
    int s =jiec(n);
    cout<<s<<endl;
}

result:

Guess you like

Origin www.cnblogs.com/caozewen/p/12175367.html