Write a function fact(int n) to find the factorial of a number n. Include a main class find the value of


import java.util.*;
class Factorial
{
    //Function
    int fact(int n)
    {
        int f=1; 
        for (int i=1; i<=n;i++)
           f=f*i;
        return(f);
    }
    //Main Function
    public static void main(String args[])
    {
        int m,n,s;
        Scanner sc=new Scanner(System.in);
        Factorial ob=new Factorial();
        System.out.println("Enter the Value of m & n = ");
        n=sc.nextInt();
        m=sc.nextInt();
        s=ob.fact(n)/(ob.fact(m)*ob.fact(n-m));
        System.out.println(s);
    }
}

No comments

Powered by Blogger.