Example Program For Factorial Value Using Function In C++


SUBMITTED BY: Nrupeshsinh

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

FORMAT: Text only

SIZE: 637 Bytes

HITS: 605

  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 Function
  20. long factorial(int n)
  21. {
  22. int counter;
  23. long fact = 1;
  24. //for Loop Block
  25. for (int counter = 1; counter <= n; counter++)
  26. {
  27. fact = fact * counter;
  28. }
  29. return fact;
  30. }

comments powered by Disqus