Skip to content

1.6 Factorial using Recursion

Farrukh Ahmad edited this page Dec 15, 2015 · 1 revision

A simple a very common use of recursion to make a product of 0 * 1 * 2 * .....*n series

for example 5 = 5 * 4 * 3 * 2 * 1 = 120

   public static void main(String args[])
{
    int n = 6;
    
    System.out.println(facto(n));
}

static int facto(int n)
{
    if (n==0 ) return 1;
    if (n==1) return 1;
    return n*facto(n-1);
}

}

Clone this wiki locally