Program C++ Perhitungan Permutasi dan Kombinasi

Beriut ini contoh Program C++ Perhitungan Permutasi dan Kombinasi :



#include <iostream.h>
#include <stdio.h>
#include <conio.h>
void main()
{
int n,r;
long int fak(long int x);
long int kombinasi (long int n, int r);
long int permutasi (long int n, int r);
char ulang;
do
{
clrscr();
cout<<endl;
cout<<" Program Menghitung Kombinasi(nCr) dan Permutasi(nPr)"<<endl;
cout<<" ===================================================="<<endl;
cout<<" Masukkan Nilai n : "; cin>>n;
cout<<" Masukkan Nilai r : "; cin>>r;
cout<<endl;

kombinasi(n,r);
permutasi(n,r);

cout<<endl ;
cout<<" Program diullangi lagi (y/n)??"<<endl;
cout<<" http://asadil.blogspot.com/2013/04/program-c-perhitungan-permutasi-dan.html";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);
}

long int kombinasi (long int n, int r)
{
int Prts;
if (n>r){
Prts = fak(n)/(fak(n-r)*fak (r));
printf(" Hasil Kombinasi nCr: %d",Prts);}
else if (n<r){
cout<<"data tak valid";}
cout<<endl;
return(Prts);
}

long int permutasi (long int n, int r)
{
int Prts;
if (n>r){
Prts = fak (n)/fak(n-r);
printf(" Hasil Permutasi nPr: %d",Prts);}
else if (n<r){
cout<<"data tak valid";}
cout<<endl;
return(Prts);
}


Semoga Bermanfaat ....

Program C++ Perhitungan Permutasi dan Kombinasi Program C++ Perhitungan Permutasi dan Kombinasi Reviewed by Arul March on 14:45 Rating: 5
Theme images by rajareddychadive. Powered by Blogger.