Dibawah ini adalah program tentang Multinomial. Silahkan dipahami dulu sebelum atau sesudah mengopy. OKE MAS BRO.
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
float x[100],p[100],fak_x[100];
int i,j,k;
cout<<"inputkan jumlah kejadian : ";cin>>k;
cout<<"\nKejadian x[1..k]\n";
for(i=1;i<=k;i++)//input kejadian x[1..k]
{
cin>>x[i];
}
cout<<"\nPeluang P[1..k]\n";
for(i=1;i<=k;i++)//input kejadian p[1..k]
{
cin>>p[i];
}
float n=0;//inisial
for(i=1;i<=k;i++)//penjumlahan x[1..k]
{
n=n+x[i];
}
float n_fak=n;//inisial
for(i=(n_fak-1);i>=1;i--)//faktorial hasil penjumlahan (n)
{
n_fak=n_fak*i;
}
for(i=1;i<=k;i++)//faktorial (x[i])
{
fak_x[i]=1;//inisial
for(j=x[i];j>=1;j--)
{
fak_x[i]=fak_x[i]*j;
}
}
float x1xk_fak=1,px1_pxk=1;//inisial
for (i=1;i<=k;i++)
{
x1xk_fak=x1xk_fak*fak_x[i];//perkalian faktorial (x[i])
px1_pxk=px1_pxk*pow(p[i],x[i]);//perkalian pangkat (p[i],x[i])
}
float n_kom_x=n_fak/x1xk_fak;
float P_Multi=n_kom_x*px1_pxk;
cout<<"\nNilai kejadian x : "<<P_Multi;
getch();
}
Semoga bermanfaat. :)
This entry was posted on 00.32 and is filed under
C++ Multinomial
. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
0 komentar: