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!
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


Join Our Facebook Group


Share this example


Download Android App

download android app

Popular C Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube