Counting permutations

in the calculation of permutations we also calculate the factorial numbers n and rbecause the number of permutations formula is nfaktorial / (nfaktorial-rfaktorial).
for more details, please my friends see the program below.

//Counting permutations

#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int nfakt,nrfakt,per;
int n,r;
nfakt=1;
nrfakt=1;
cout<<”\t\t\tMENGHITUG NILAI PERMUTASI”<<endl;
cout<<”\t\t======================================”<<endl;
cout<<endl;
cout<<”masukkan nilai n:”;
cin>>n;
cout<<”masukkan nilai r:”;
cin>>r;
for(int i=n;i>0;i–)
{
nfakt=nfakt*i;
}
for(int i=n-r;i>0;i–)
{
nrfakt=nrfakt*i;
}
per=nfakt/nrfakt;
cout<<”nilai permutasinya adalah:”<<per<<endl;
cout<<endl;
system(“PAUSE”);
return EXIT_SUCCESS;
}

Leave reply

Back to Top