Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Last active December 9, 2019 22:21
Show Gist options
  • Save gavinsykes/bd2066cb4f1ed221d498ca54a68f2eb7 to your computer and use it in GitHub Desktop.
Save gavinsykes/bd2066cb4f1ed221d498ca54a68f2eb7 to your computer and use it in GitHub Desktop.
Project Euler Problem 15 in C
#include <stdio.h>
int nCr(int n,int r);
int factorial(int n);
int main() {
int n;
scanf("Please enter a number here: %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