Write C program to find factorial of a number using recursion


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Write C program to find factorial of a number using recursion


  1. #include <stdio.h>
  2.  
  3. // Function declaration
  4. unsigned long long Findfact(int num);
  5.  
  6.  
  7. int main()
  8. {
  9. int num;
  10. unsigned long long factorial;
  11.  
  12. // Inputting an integer from user
  13. printf("Enter any number: ");
  14. scanf("%d", &num);
  15.  
  16. factorial = Findfact(num);
  17.  
  18. printf("Factorial of %d is %llu", num, factorial);
  19.  
  20. return 0;
  21. }
  22.  
  23. unsigned long long Findfact(int num)
  24. {
  25. // Base condition
  26. if(num == 0)
  27. return 1;
  28. else
  29. return num * Findfact(num - 1);
  30. }
  31.  

Result

C language

     





Related Topics




Popular Posts