Created
November 30, 2020 23:48
-
-
Save gavinsykes/887f2e6edc4aeafbc0a42392a5905077 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <stdio.h> | |
int nCr(int n,int r); | |
int factorial(int n); | |
int main() { | |
int n; | |
printf("Please enter a number here:\n"); | |
scanf("%d",&n); | |
printf("Here is your answer: %d\n",nCr(2*n,n)); | |
return 0; | |
} | |
int nCr(int n,int r) { | |
int result = factorial(n) / (factorial(r) * factorial(n-r)); | |
return result; | |
} | |
int factorial(int n) { | |
int result = 1; | |
while (n > 1) { | |
result *= n; | |
n--; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment