Sunday, February 24, 2019

RECURSION

int fact(int n)
{
    if (n < = 1) // base case
        return 1;
    else    
        return n*fact(n-1);    
}
The above program calculates ' factorial n ' . 
The code calls it self and the few lines performs magic.
 The logic: n*(n-1}......3*2*1.