diff --git a/C++/Factorial.cpp b/C++/Factorial.cpp index 19c330bf6..617f10435 100644 --- a/C++/Factorial.cpp +++ b/C++/Factorial.cpp @@ -3,18 +3,27 @@ using namespace std; int factorial(int n) { - if(n > 1) - return n * factorial(n - 1); + if(n<0) + { + return(-1); //Corresponds to wrong value + } + if(n==0) + { + return(1); //Terminating condition + } else - return 1; - + { + return(n*factorial(n-1)); //recursive call + } } int main() { - int n; - cout << "Enter a positive integer: "; - cin >> n; - cout << "Factorial of " << n << " = " << factorial(n); + int factorial(int); + int fact,n; + cout<<"Enter the number of which u wish to get factorial"<>n; + fact=factorial(n); + cout<<"Factorial of the number you entered is "<