#include <cstdlib> #include <iostream> using namespace std; class kombinatorial{ public: void permutasi(); void combinasi(); private: int i,n,r,p,t,a,b,c; }; void kombinatorial::permutasi(){ cout<<"PERMUTASI"<<endl; cout<<"Masukan n:"; cin>>n; cout<<"Masukan r:"; cin>>r; a=1; b=1; for(i=n;i>0;i--) { a *=i; } t=n-r; if(t!=0) { for(i=t;i>0;i--) { b *=i; } } if(t!=0) { p=a/b; cout<<"Hasil:"<<p<<endl; } else { cout<<a<<endl; } } void kombinatorial::combinasi(){ cout<<"COMBINASI"<<endl; cout<<"Masukan n:"; cin>>n; cout<<"Masukan r:"; cin>>r; a=1; b=1; c=1; for(i=n;i>0;i--) { a *=i; } t=n-r; if(t!=0) { for(i=t;i>0;i--) { b *=i; } } for(i=r;i>0;i--) { c *=i; } if(t!=0) { p=a/(b*c); cout<<"Hasil:"<<p<<endl; } else { cout<<a<<endl; } } int main(int argc, char *argv[]) { kombinatorial x; x.permutasi(); cout<<endl; x.combinasi(); cout<<endl; system("PAUSE"); return EXIT_SUCCESS; }
0 Response for the "Program Menentukan Kombinasi Dan Permutasi"
Post a Comment