I'm trying to get the factorial of 5, for example, but it won't let me. I've tried almost everything but I can't seem to figure it out. Thanks for taking the time to read.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
void factorial(int n) {
for(int i = 1; i <= n; i++) {
cout << 1 * (n - 1);
}
}
int main() {
int x;
cout << "Enter a number to see its factorial: ";
cin >> x;
factorial(x);
}
I want to increment variable i (1, 2, 3, 4, 5) and as the incrementation is occurring, I want it to get multiplied, too. I want to n print the factorial of the inputted number.
On lines 6 and 7, which variable is being incremented? Which one are you printing?
I fully understand what you want to do, but I am trying to get you to think about what is happening, perhaps I should have said which variable name is being incremented? i or n ?
To do this you need another variable. We start with 1 * 2, we need to put the answer to that somewhere.