#include <iostream>
usingnamespace std;
long fact(int n)
{
if (n<0)
return 0;
int f(1);
while (n>0, f<n)
n *= f++;
return n;
}
int main()
{
int x;
cin >> x;
cout << fact(x);
system ("pause");
return 0;
}
1) while (n>0, f<n) is equivalent to while (f<n)
2) you are multiplying n byf (making it way larger than it was before) and increment f (making it slightly larger). n increases faster than f and f will always be less than n... until n overflows, after that anything could happen.