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.



  1. //C program for factorial recursion
  2. #include<stdio.h>
  3. int facto(int);
  4. int main()
  5. {
  6. int n, f;
  7. printf("\nEnter any integer number:");
  8. scanf("%d",&n); //taking input from user
  9. f=facto(n); //calling the recursive function
  10. printf("\nfactorial of %d is: %d",n, f); //output
  11. return 0;
  12. }
  13. int facto(int n) //recursive function facto
  14. {
  15. if(n==0)
  16. return(1);
  17. return(n*facto(n-1));
  18. }

Output


Output!