Write C++ program to find factorial of a number using recursion


I have used CodeBlocks 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

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Function declaration
  5. unsigned long long Findfact(int num);
  6.  
  7. int main()
  8. {
  9. int num;
  10. unsigned long long factorial;
  11.  
  12. // Inputting an integer from user
  13. cout<<"Enter any number: ";
  14. cin>>num;
  15.  
  16. factorial = Findfact(num);
  17.  
  18. cout<<"Factorial of " <<num<< " is "<<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 techstudy.org

     





Related Topics




Popular Posts