#include
int pilih,n,r;
int faktorial(int n)
{
int fak;
for(int i=1;i<=n;i++)
{
fak=1;
{
for(int j=1;j<=i;j++)
{
fak=fak*j;
}
}
}
return fak;
}
int permutasi(int n, int r)
{
int tamp,permutasi;
tamp=n-r;
permutasi=faktorial(n)/faktorial(tamp);
return permutasi;
}
int kombinasi(int n, int r)
{
int tamp,kombinasi;
tamp=n-r;
kombinasi=faktorial(n)/(faktorial(r)*faktorial(tamp));
return kombinasi;
}
int fibonaci(int n)
{
int f=1,f2=1,fibo=0;
for(int i=1;i>=0;i++)
{
fibo=f+f2;
f=f2;
f2=fibo;
return fibo;
}
if(n!=fibo)
printf("Bukan bilangan fibonacci\n");
else
printf("Bilangan fibonacci\n");
}
void main()
{
printf("Pilihan rumus : \n");
printf("1. Faktorial\n");
printf("2. Permutasi\n");
printf("3. Kombinasi\n");
printf("4. Cek fibonacci\n");
printf("\n");
printf("Masukkan pilihan : ");scanf("%i",&pilih);
switch(pilih)
{
case 1 :
int n,hasil;
printf("Masukkan n : ");scanf("%i",&n);
hasil=faktorial(n);
printf("Faktorial %i = %i\n",n,hasil);
break;
case 2 :
int a,r,jumlah;
printf("Masukkan a : ");scanf("%i",&a);
printf("Masukkan r : ");scanf("%i",&r);
jumlah=permutasi(a,r);
printf("Permutasi : %i\n",jumlah);
break;
case 3 :
int x,y,h;
printf("Masukkan x : ");scanf("%i",&x);
printf("Masukkan y : ");scanf("%i",&y);
h=kombinasi(x,y);
printf("kombinasi : %i\n",h);
break;
case 4 :
int l;
printf("Masukkan bil : ");scanf("%i",&l);
fibonaci(l);
break;
default : printf("Pilihan tidak ada..\n");
}
}
Home » algoritma » Permutasi, Kombinasi, Faktorial, Fibonacci
Permutasi, Kombinasi, Faktorial, Fibonacci
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment