Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Mathematical/combinations.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <stdio.h>

long int factorial(long int n);

long int calcomb(long int n,long int r);

int main(){

long int n=0,r=0;

printf("This is a Program to calculate the combinations of r things out of n things\nEnter the value of n and r\n");

scanf("%ld%ld", &n, &r);

if(r>n){

printf("Wrong input detected\nGive input in the range 0<=r<=n\n");

return 0;
}

printf("The combinations of r things out of n things is\t%ld",calcomb(n,r));

return 0;
}

long int factorial(long int n){

if(n<=0){
return 1;
}

else{

return (n)*factorial(n-1);
}
};

long int calcomb(long int n,long int r){

return (factorial(n)/(factorial(r)*factorial(n-r)));
};