Saturday 23 July 2016

Q.8: Factorial of Given number using Recursion.
class  Factorial
{
long fact(int n)
{
if(n==0||n==1)
return 1;
else
return n*fact(n-1);
}

public static void main(String[] args) 
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
Factorial f=new Factorial();
long fact=f.fact(n);
System.out.println("Factorial of given Num is: "+fact);

}
}

7 comments:

Featured post

All Logical Questions are Answered JumpInToIt