Last active
December 9, 2019 22:21
-
-
Save gavinsykes/bd2066cb4f1ed221d498ca54a68f2eb7 to your computer and use it in GitHub Desktop.
Project Euler Problem 15 in C
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 <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