-
-
Save mochadwi/3dfbdebdd3d46d7e52a3024757a70e23 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 angka N:"; | |
cin>>n; | |
cout << endl; | |
cout<<"Masukkan angka K:"; | |
cin>>k; | |
cout << endl; | |
cout<< "C(n, 0) = " << binomial(n,0) << endl; //kondisi binomial(n,0); | |
cout<< "C(n, n) = " << binomial(n,n) << endl; //kondisi binomial(n,n); | |
cout<< "C(n, k) = " << binomial(n,k) << endl; //kondisi binomial(n,k); | |
} | |
int binomial(int n, int k) | |
{ | |
if(n>=0 && (k==0 || k==n)) //kondisi binomial(n,0) atau binomial(n,n); | |
{ | |
return 1; | |
} | |
else if (n>k && k>0) //kondisi binomial(n,k); | |
{ | |
return (binomial(n-1,k)) + (binomial(n-1,k-1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment