-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrecursion.c
More file actions
46 lines (38 loc) · 922 Bytes
/
Copy pathrecursion.c
File metadata and controls
46 lines (38 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// #include<stdio.h>
// void printHW(int count);
// int main()
// {
// printHW(5);
// return 0;
// }
// void printHW(int count){
// if (count == 0)
// {
// return;/* code */
// }
// printf("Hello univision \n");
// printHW(count-1); // call the function itself
// }
// //write a program to find the factorial of a given number using a recursion function.
#include<stdio.h>
int find_factorial(int);
int main()
{
int num, fact;
//Ask user for the input and store it in num
printf("\nEnter any integer number:");
scanf("%d",&num);
//Calling our user defined function
fact =find_factorial(num);
//Displaying factorial of input number
printf("\nfactorial of %d is: %d \n",num, fact);
return 0;
}
int find_factorial(int n)
{
//Factorial of 0 is 1
if(n==0)
return(1);
//Function calling itself: recursion
return(n*find_factorial(n-1));
}