From 8562ad37dfcbfb7adc2b1c0c3c0890337c9b1f89 Mon Sep 17 00:00:00 2001 From: pulkit-M <56073771+pulkit-M@users.noreply.github.com> Date: Sat, 12 Oct 2019 17:25:27 +0530 Subject: [PATCH] Update factorial.c --- Maths/Factorial/C/factorial.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Maths/Factorial/C/factorial.c b/Maths/Factorial/C/factorial.c index 818b68ce..5ce0b98c 100644 --- a/Maths/Factorial/C/factorial.c +++ b/Maths/Factorial/C/factorial.c @@ -1,16 +1,19 @@ #include "stdio.h" +/*Recursive program to find Factorial + of Small numbers*/ - -long long factorial(long long n) { - if(n == 1) { - return 1; - } - else { - return n * factorial(n-1); - } +long long int factorial(long long n) { + if(n == 1||n == 0) { + return 1; + } + else { + return n * factorial(n-1); + } } int main(int argc, char * argv[]) { - printf("Enter a number"); - scanf("%d",&n); + long long int n; + printf("Enter a number:"); + scanf("%lld",&n); + printf("Factorial:%lld\n",factorial(n)); }