About Me

programming in java 2nd year

java
factorial using  recursion

class Factorial
{
  public static void main(String args[])
  {
     for(int i=1;i<=5;i++)
     {
         system.out.println("Factorial of " + i+"is:" fact(i));
      }
}

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

output:
Factorial of 1 is:1
Factorial of 2 is:2
Factorial of 3 is:6
Factorial of 4 is:24
Factorial of 5 is:120

Post a Comment

0 Comments

Welcome

BODY

How to prevent Right Click option using jquery

Try right-click on the page