Created
February 13, 2017 13:44
-
-
Save corinchen/e9f2a4321a8e4716bf56bbe94df7ce37 to your computer and use it in GitHub Desktop.
binomial fix lho~
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int binomial(int n, int k); | |
int main() | |
{ | |
int n,k; | |
cout<<"\t\t\t Program menghitung Fungsi Binomial\t\t\t"; | |
cout<<endl; | |
cout<<"Masukkan 2 angka :"; | |
cin>>n>>k; | |
if(n>=0 && k==0) //kondisi binomial(n,0); | |
{ | |
cout<<binomial(n,0); | |
} | |
else if(n>=0 && k==n) //kondisi binomial(n,n); | |
{ | |
cout<<binomial(n,n); | |
} | |
else if (n>k>0) //kondisi binomial(n,k); | |
{ | |
cout<<binomial(n,k); | |
} | |
} | |
int binomial(int n, int k) | |
{ | |
if(n>=0 && k==0) //kondisi binomial(n,0); | |
{ | |
return(1); | |
cout<<binomial(n,0); | |
} | |
else if(n>=0 && k==n) //kondisi binomial(n,n); | |
{ | |
return(1); | |
cout<<binomial(n,n); | |
} | |
else if (n>k && k>0) //kondisi binomial(n,k); | |
{ | |
return (binomial(n-1,k)) + (binomial(n-1,k-1)); | |
cout<<binomial(n,k); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment