10776 - Determine The Combination UVA Online Judge Solve with Java

6:34 AM | , , , , , ,



import java.util.Scanner;
class Combinations {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int M=-1,N=-1;
        while((M!=0)&&(N!=0)){
            N=s.nextInt();
            M=s.nextInt();
            long C,a=1,b=1;
            for (int i = 1; i <=M; i++) {
               a*=(N-i+1);
               b*=i;
            }
            C=a/b;
            System.out.println(N+" things taken "+M+" at a time is "+C+" exactly");
        }
    }
}

0 comments:

Post a Comment

Please leave a comment