Skip to content

Commit c68c9c0

Browse files
Update Recursion-factorial.c
Formatted the code and added comments for better readability
1 parent 262515e commit c68c9c0

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

Recursion/Recursion-factorial.c

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
#include<stdio.h>
2-
int fact(int n){
3-
if(n==0)
4-
return 1;
5-
else
6-
return n*fact(n-1);
7-
}
8-
void main(){
1+
// This program finds the Factorial of a number using recursion
2+
3+
// Importing Header File
4+
#include <stdio.h>
5+
6+
// Function to find factorial
7+
int fact(int n)
8+
{
9+
if (n == 0)
10+
return 1;
11+
else
12+
return n * fact(n - 1);
13+
}
14+
15+
// Main function
16+
void main()
17+
{
918
int n;
10-
printf("enter number");
11-
scanf("%d",&n);
12-
printf("Factorial is %d",fact(n));
13-
}
19+
printf("enter number");
20+
scanf("%d", &n);
21+
printf("Factorial is %d", fact(n));
22+
}

0 commit comments

Comments
 (0)