Advertisement
Tiger6117

factorial using recursive function

Jul 26th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. //Coded and executed on CodeBlock
  2. // C++ Code for factorial using recursive function
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. int fact(int x)
  9. {
  10.     double f=1;;
  11.     if(x==1)
  12.     {
  13.         return 1;
  14.     }
  15.     else{
  16.         f=x*fact(x-1);
  17.         return f;
  18.     }
  19. }
  20.  
  21. int main()
  22. {
  23.     int n;
  24.     cout << "\t\tFactorial Finder \n";
  25.     cout << "Enter Number : ";
  26.     cin >>n;
  27.     cout << fact(n);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement