Selasa, 05 Juli 2011

Compute Combinations and Permutations

The combination is to combine several objects from a group without regard to order. In combination, the order is not considered. combination combinatorics in mathematics means the set of objects that are not concerned with the order. The combination of different permutations of the importance of the object sequence. R The number of combinations of a set containing n elements can be calculated without having to pay attention to the contents of the set. The magnitude is expressed by the function: Function in a lot of literature is also expressed by the notation.
Permutation (nPr) is to combine several objects from a group with respect to the order. In the permutation, the order of the sequence diperhatikan.Jika note and every object that is available can be selected or used only once then the number of permutations that exist are:
 where n is the number of objects you can choose, r is the amount that must be selected and! is the factorial symbol
For example, there is a vote in an organization. Candidates can choose any five people. Who gets the most votes will be appointed chairman of the organization. Who received the second most votes will be appointed vice chairman. And the third most votes will be the secretary. How many voting results that might happen? Using the formula above, there are 5! / (5-3)! = 60 permutations.
Pejumlahan and Multiplication Rules
Addition rule
The set S is partitioned into subsets S1, S2, ... ... ... Sm
The number of objects in S = number of objects of all subsets
Example 1: This type of IBM computer (3), Apple (2) and HP (2)
The number of choices there are 3 + 2 + 2
multiplication rule
Set A has p elements and B has q elements
The number of combinations (a, b) = p x q
(Masing2 considered different combinations)
Example 2:
Two dice (red and green) were thrown together
The number of different results: 6 x 6
When the results should not be double: 6 x 5

#include <iostream.h>                                                 
#include <stdio.h>
#include <conio.h>
long int fak (long int x);
void main(){
int n,r, Prts,pilihan,p;
char ulang;
do{
clrscr();
cout<<"      Nama: Desmala Dewi "<<endl;
cout<<"      NIM : 10018061 "<<endl;
cout<<"      Alamat: jln. Nalen UH 192/36"<<endl<<endl;
cout<<"==================================="<<endl;
cout<<"Menghitung Kombinasi & Permutasi"<<endl;
cout<<"==================================="<<endl;
cout<<"=    1. Kombinasi                 ="<<endl;
cout<<"=    2. Permutasi                 ="<<endl;
cout<<"=    3. keluar                    ="<<endl;
cout<<"==================================="<<endl;
cout<<"Mana aj boleh: ";cin>>pilihan;
 
switch (pilihan){
case 1 :
cout<<" Itung-itung Kombinasi donk(nCr)";
cout<<endl;
cout<<" Punya n : "; cin>>n;
cout<<endl;
cout<<" Punya r : "; cin>>r;
cout<<endl;
if (n>r){
Prts = fak(n)/(fak(n-r)*fak (r));
cout<<endl;
printf(" Kom-kombinasinya : %d",Prts);
cout<<endl; }
else if (n<r){
cout<<"data tak valid";}
cout<<endl ;
break;
 
case 2 :
cout<<" cari-cari Permutasi(nPr)";
cout<<endl;
cout<<" Milik n : "; cin>>n;
cout<<endl;
cout<<" Milik r : "; cin>>r;
cout<<endl;
if (n>r){
Prts = fak (n)/fak(n-r);
cout<<endl;
printf(" Permu-muttasinya adalah: %d",Prts);
cout<<endl; }
else if (n<r){
cout<<"data tak valid";}
cout<<endl ;
break;
case 3 :
cout<<"Exit�"<<endl;
break;
default:
cout<<"Menu tidak tersedia"<<endl;
break;}
cout<<"Mau balikan gx (y/n)?";cin>>ulang;
}while(ulang == 'y');}
 
getch();
long int fak (long int n){
int f;
if (n<=1){
f=1;}
else{
f=n*fak(n-1);
 }  
return (f);}








Tidak ada komentar:

Posting Komentar