Hey all, i'm having a bit of trouble with this - it's a program that should display the factorials of all numbers from 0 to k in the range 1-10. here's what i keep getting:
Enter a number to see factorials for: 1010! = 100
9! = 90
8! = 80
7! = 70
6! = 60
5! = 50
4! = 40
3! = 30
2! = 20
1! = 10
The factorial of 10 is 3628800
Press any key to continue . . .
...and here is what it needs to look like:
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
Any help would be SO appreciated! Thanks all :)
#include<iostream>
using namespace std;
int factorial(int);
void main()
{
int x;
int factorial=1;
cout << "Enter a number to see factorials for: ";
cin >> x;
cout << "\n";
for (int i = x; i; i--)
{
cout << i << "!"<< " = " << (i*x)<<endl;
factorial *= i;
}
cout << "The factorial of "<<x<<" is "<<factorial<<endl;
}
int factorial(int n)
{
if (n <= 1) return 1;
return n * factorial(n-1);
}