Example Program For Factorial Value Using Recursion In C++


SUBMITTED BY: Nrupeshsinh

DATE: June 24, 2016, 8:26 a.m.

FORMAT: Text only

SIZE: 535 Bytes

HITS: 603

  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. //Function
  5. long factorial(int);
  6. int main()
  7. {
  8. // Variable Declaration
  9. int counter, n;
  10. // Get Input Value
  11. cout<<"Enter the Number :";
  12. cin>>n;
  13. // Factorial Function Call
  14. cout<<n<<" Factorial Value Is "<<factorial(n);
  15. // Wait For Output Screen
  16. getch();
  17. return 0;
  18. }
  19. // Factorial recursion Function
  20. long factorial(int n)
  21. {
  22. if (n == 0)
  23. return 1;
  24. else
  25. return(n * factorial(n-1));
  26. }

comments powered by Disqus