How do I get rid of the zero digit in this program? this is a factorial problem and I have to show the numbers to be multiplied before arriving to the answer. The problem is, in the iteration process, the number zero will show. How do I get rid of it? thanks.
Here's my code:
#include <iostream>
#include <conio.h>
using namespace std;
int fac(int num);
int main ()
{
int num;
cout << "Enter a non-negative integer: ";
cin >> num;
cout << endl;
cout << num << "! = " << "(" << num << ")"<< "";
cout << "\n\nThe factorial of " << num << " is " << fac(num) << endl;
system("PAUSE");
return 0;
}
int fac(int num)
{
int factorial = 1;
for (int i = 1; i <= num; i++)
{
factorial *= i;
cout << "(" << num-i << ")" << "";
}
return factorial;
}
Thanks!