PROGRAM Permutasi;
DEKLARASI
m,n,r:integer;
fak1,fak2,perm:real;
ALGORITMA
read(n,r)
m<-n-r;
fak1<-1;
fak2<-1;
if m<0 then
write ('angka yang dimasukkan salah')
else
while n>0 do
fak1<-fak1*n
n<-n-1;
endwhile
while m>0 do
fak2<-fak2*m;
m<-m-1;
endwhile
endif
perm<-fak1/fak2;
write(perm);
KODING
using namespace std;
int main(){
int n,r,m;
float fak1,fak2,perm;
cout<<"PROGRAM PERMUTASI"<<endl;
cout<<"Masukan nilai n= "; cin>>n;
cout<<"Masukkan nilai r="; cin>>r;
m=n-r;
fak1=1;
fak2=1;
if (m<0)
cout<<"Angka yang dimasukkan salah"<<endl;
else
while (n>0){
fak1=fak1*n;
n=n-1;
}
while (m>0){
fak2=fak2*m;
m=m-1;
}
perm=fak1/fak2;
cout<<"P(n,r)= "<<perm<<endl;
system("PAUSE");
}
KLIK DISINI UNTUK DOWNLOAD
No comments:
Post a Comment