From 1cba62a5274cadb6fff64bd21fb834fd2aff5aa1 Mon Sep 17 00:00:00 2001 From: Jebin Philipose Date: Sun, 1 Oct 2017 22:40:42 +0530 Subject: [PATCH] Add: Implementation of factorial in C --- math/factorial/C/factorial.c | 17 +++++++++++++++++ math/factorial/README.md | 8 ++++++++ 2 files changed, 25 insertions(+) create mode 100644 math/factorial/C/factorial.c create mode 100644 math/factorial/README.md diff --git a/math/factorial/C/factorial.c b/math/factorial/C/factorial.c new file mode 100644 index 0000000000..718b1f956f --- /dev/null +++ b/math/factorial/C/factorial.c @@ -0,0 +1,17 @@ +#include + +long long fact(long long x) +{ + if(x > 1) + return x*fact(x-1); + else return 1; +} + +int main(void) +{ + int n, t, s=0, r; + printf("Enter the number: "); + scanf("%d", &n); + printf("\nFactorial of the number is: %lld",fact(n)); + return 0; +} \ No newline at end of file diff --git a/math/factorial/README.md b/math/factorial/README.md new file mode 100644 index 0000000000..8375793ffc --- /dev/null +++ b/math/factorial/README.md @@ -0,0 +1,8 @@ +### Factorial + +Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. For example factorial of 6 is 6*5*4*3*2*1 which is 720. + +#### Example: + +Input : 4
+Output : 24