Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main(){
- // factorial starts at 1
- // number = 1 is needed to store term, to multiply the term after another term has been created
- // store stores input to store 1 without affecting input for if
- // final multiplies input with number
- double input, factorial = 1, term, store, number = 1, final;
- cout << "Enter a Number: ";
- cin >> input;
- cout << input << "!" << " is ";
- store = input;
- if (input==0){
- store = 1;
- }
- else if (input!=0){
- do{
- if (factorial<=store - 1){
- //(n - 1) ... (n - (store - 1)
- // stops when factorial <= store - 1
- term = input - factorial;
- }
- //(n - 1)(n - 2) ... stops when factorial <= store - 1
- number *= term;
- factorial++;
- }while (factorial<=store - 1);
- }
- //n(n - 1)(n - 2) ...
- final = store * number;
- cout << setprecision(0) << fixed << final;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement