The output of my code is:
5! = 1 * 2 * 3 * 4 * 5 * = 120
How can I remove the last *
to have this output:
5! = 1 * 2 * 3 * 4 * 5 = 120
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
int n, count, factorial = 1;
cout << "Enter a positive integer: ";
cin >> n;
cout << n << "! = ";
if (n < 0){
cout << "Error! Factorial of a negative number doesn't exist.";
}
else{
while(count < n){
count++;
factorial = factorial * count ;
cout << count << " * ";
}
cout << " = " << factorial;
}
}