-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
456e345
commit e298c11
Showing
1 changed file
with
14 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |