Buat program menghitung nilai
Kombinasi
P E N Y E L E S A I A N :
package soalno2;
import java.util.*;
public class Main {
public static void main(String[] args) {
System.out.println("Menghitung Nilai Kombinasi");
System.out.println("_________________________________");
int n;
int r;
Scanner x = new Scanner(System.in);
System.out.print("Masukan bilangan n = ");
n = x.nextInt();
System.out.print("Masukan bilangan r = ");
r = x.nextInt();
int o=1;
int s=1;
int p, q;
for(p=n;p>=1;p--) {
o*=p;
}
q=(n-r);
for(r=q;r>=1;r--) {
s*=r;
}
System.out.println(n+"P"+r+" = "+(o/s));
}
}
H A S I L :
0 komentar:
Post a Comment