Factorial Table

I made a program that finds the factorials. However, the next step is that I need to put it in table format. To output how the computer came up with that answer. For example if I input 3 the answer is 6. (1*2*3*4) If I input 5 the answer is 120. (1*2*3*4*5)

Can someone please show me how to cout the (counter * counter+ * counter++ * counter++) depending on the number (1-5) it will cout that many counter increments? So 3=3 counter increments. 5=5 counter increments 1 = 1 counter 2= 2 counter increments, etc.

Did I explain that right?

I'm totally stuck on how to put it in table format after it displays the factorial answer. I have a feeling it has to do with decrement or incrementing the counter variable?

So the output should be something like:
1 1
2 1*2
3 1*2*3
4 1*2*3*4
5 1*2*3*4*5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
int main ()
{
    int counter=0;
	int product = 1;
    cout << "Enter a whole number from 1 to 5:";
    cin >> counter;
    
    while ( counter>1) { 
    
        product *= counter--;
    }
	cout << "The factorial is: " << product;
	cout << "" --counter;

	
 return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main()
{
    cout << inputNum << "'s factorial is: ";
    for(i; i <=inputNum; i++) {
        if(i == inputNum) {
           answer *= i;
           cout << " " << i << " = "<< answer;
           break;
        }
        else
           cout << i <<" * ";
        answer *= i;
    }
    
    cin.get();
    return 0;
}    


Note * not tested as there is no compiler on this computer, looks right though...

Note ** now tested.
Last edited on
Topic archived. No new replies allowed.