package com.alok;
import java.util.Scanner;
class Cal
{
int fact(int n)
{
if(n==0 || n==1)
return 1;
else
return fact(n-1)*n;
}
}
public class Factorial
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number for factorial");
int n=sc.nextInt();
Cal c=new Cal();
int f=c.fact(n);
System.out.println("Factorial of "+n+" is : "+f);
}
}
O/P :-
Enter number for factorial
6
Factorial of 6 is : 720
No comments:
Post a Comment