C Program to Calculate Factorial Using Recursion
Factorial, in mathematics, the product of all positive integers less than or equal to a given positive integer and denoted by that integer and an exclamation point. Thus, factorial seven is written 7!, meaning 1 × 2 × 3 × 4 × 5 × 6 × 7. Factorial zero is defined as equal to 1.
- //C program for factorial recursion
-
- #include<stdio.h>
- int facto(int);
- int main()
- {
- int n, f;
- printf("\nEnter any integer number:");
- scanf("%d",&n); //taking input from user
- f=facto(n); //calling the recursive function
-
- printf("\nfactorial of %d is: %d",n, f); //output
- return 0;
- }
- int facto(int n) //recursive function facto
- {
-
- if(n==0)
- return(1);
-
- return(n*facto(n-1));
- }
Output
