Program Bilangan Kombinasi C++
#include <stdio.h>
long int faktorial(int);
int permutasi(int, int);
int kombinasi(int, int);
main ()
{
int n, r;
printf("MENCARI PERMUTASI DAN KOMBINASI\n");
printf("RUMUS Permutasi : P (n, r) = n! / (n-r)!\n");
printf("RUMUS Kombinasi : C(n, r)=n!/r!(n-r)!\n");
printf("\nMasukkan nilai n = ");
scanf("%d", &n);
printf("\nMasukkan nilai r = ");
scanf("%d", &r);
printf("\n n = %d r = %d \n",n,r);
printf("\n%d data dipermutasikan %d = %d\n", n, r, permutasi(n,r));
printf("\n%d data dikombinasikan %d = %d\n\n", n, r, kombinasi(n,r));
}
long int faktorial(int x)
{ int fak, i;
fak = 1;
for(i = 1; i<=x; i++)
fak = fak * i;
return(fak);
}
int permutasi(int n, int r)
{ int hasil, temp;
temp = n - r;
hasil = faktorial(n) / faktorial(temp);
return(hasil);
}
int kombinasi(int n, int r)
{ int hasil, temp;
temp = n - r;
hasil = faktorial(n) / (faktorial(r) * faktorial(temp));
return(hasil);
}
Matur Sembah Nuwun
long int faktorial(int);
int permutasi(int, int);
int kombinasi(int, int);
main ()
{
int n, r;
printf("MENCARI PERMUTASI DAN KOMBINASI\n");
printf("RUMUS Permutasi : P (n, r) = n! / (n-r)!\n");
printf("RUMUS Kombinasi : C(n, r)=n!/r!(n-r)!\n");
printf("\nMasukkan nilai n = ");
scanf("%d", &n);
printf("\nMasukkan nilai r = ");
scanf("%d", &r);
printf("\n n = %d r = %d \n",n,r);
printf("\n%d data dipermutasikan %d = %d\n", n, r, permutasi(n,r));
printf("\n%d data dikombinasikan %d = %d\n\n", n, r, kombinasi(n,r));
}
long int faktorial(int x)
{ int fak, i;
fak = 1;
for(i = 1; i<=x; i++)
fak = fak * i;
return(fak);
}
int permutasi(int n, int r)
{ int hasil, temp;
temp = n - r;
hasil = faktorial(n) / faktorial(temp);
return(hasil);
}
int kombinasi(int n, int r)
{ int hasil, temp;
temp = n - r;
hasil = faktorial(n) / (faktorial(r) * faktorial(temp));
return(hasil);
}
Matur Sembah Nuwun
Komentar
Posting Komentar