Skip to content

Commit

Permalink
Update factorial.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
TanujRohilla authored Oct 1, 2018
1 parent 456e345 commit e298c11
Showing 1 changed file with 14 additions and 33 deletions.
47 changes: 14 additions & 33 deletions factorial/factorial.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;


int factorial(int n)
{
return (n==1 || n==0) ? 1: n * factorial(n - 1);
}
using namespace std;

int factorial (int n)
{
if(n==1)
{
return 1;
}
return n*factorial(n-1);

}
int main()
{
int num, fact, aux;
vector<int>results;
results.push_back(1);
results.push_back(1);
char c;
while(true){
fact = 1;
cout << "Enter the number you want to find factorial of: ";
cin >> num;
factorial(num);

//optimised and short code of factorial
cout <<"Factorial of "<< num <<" is: "<< fact << endl;
cout <<"Do You Want to Enter another number?(y/n): ";
cin>>c;
if(c=='n' || c=='N')
{
exit(0);
}
else
{
continue;
}
}
return 0;
int n,result;
cin>>n;
result=factorial(n);
cout<<result;
return 0;

}

0 comments on commit e298c11

Please sign in to comment.