Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /* factorial */
- int fact(int n){
- if(n == 0){
- return 1;
- } else {
- return n * fact(n-1);
- }
- }
- /* combination */
- int comb(int n, int r){
- if(n == r){
- return 1;
- }
- if(r >= n){
- printf("please enter n > r > 0 \n");
- return 0;
- }
- return fact(n) / (fact(r) * fact(n-r));
- }
- int main(){
- // test case 1, di bawah 12
- printf("case 1 = %d\n", comb(8, 4));
- // test case 2, di atas 12
- printf("case 2 = %\n", comb(17,13));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement