From 5f37bf8ef9948239c38edfd1dcb16c0c66631cfd Mon Sep 17 00:00:00 2001 From: Aashirwad Tyagi <90493290+aashirwadtyagi@users.noreply.github.com> Date: Tue, 1 Nov 2022 23:44:43 +0530 Subject: [PATCH] =?UTF-8?q?Update=20Exercise=201=20-=20L=C3=A9o.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Exercise 1 - L\303\251o.c" | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git "a/2021 Feb Lab Sheets/Lab Sheet 11/Lab Sheet 11 - L\303\251o/Exercise 1 - L\303\251o.c" "b/2021 Feb Lab Sheets/Lab Sheet 11/Lab Sheet 11 - L\303\251o/Exercise 1 - L\303\251o.c" index b7b97e1..336fa0e 100644 --- "a/2021 Feb Lab Sheets/Lab Sheet 11/Lab Sheet 11 - L\303\251o/Exercise 1 - L\303\251o.c" +++ "b/2021 Feb Lab Sheets/Lab Sheet 11/Lab Sheet 11 - L\303\251o/Exercise 1 - L\303\251o.c" @@ -1,19 +1,21 @@ -#include - -int main() -{ - int x,facto=1; - - printf("Enter Number: "); - scanf("%d",&x); - - printf("Factorial of %d is: ",x); - - while(x!=0) - { - facto *= x; - x--; - } - - printf("%d",facto); -} +#include + +long factorial(int n) +{ + if (n == 0) + return 1; + else + return(n * factorial(n-1)); +} + +void main() +{ + int number; + long fact; + printf("Enter a number: "); + scanf("%d", &number); + + fact = factorial(number); + printf("Factorial of %d is %ld\n", number, fact); + return 0; +}