factorial(x--,y*z,z++);
You're passing the current value of x to factorial(), recursion never stops and you experience a stack overflow.
deceptikon
Challenge Accepted
3,428 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56
In addition to what Deceiptikon and sepp2k said, I would add that it yu've declared the function as returning an int value, but at no point to you actually return one.
There is actually a much simpler way to do this, one which takes only the starting value as an argument and returns it's factorial. If you think through the definition of a factorial, it is
N! = N * (N-1)!
which could, as an example, be expanded to get
N! = N * (N - 1) * (N - 2)!
N! = N * (N - 1) * (N - 2) * (N - 3)!
N! = N * (N - 1) * (N - 2) * (N - 3) * (N - 4)!
and so forth, eventually giving
N! = N * (N - 1) * ... 1
meaning that all you need to do to calculate N! is to first calculate (N - 1)!, then multiply that by N. From this, the answer should be straightforward: just re-write the definition into C code.
int factorial(int x)
{
if (x <= 1)
return 1;
else
return ??? // insert factorial definition here, in C code
}
This should be very easy to understand and implement; I've given you more than enough, too much very likely, and will leave the remaining half a line of code to you.
Schol-R-LEA
Veteran Poster
1,022 posts since Oct 2010
Reputation Points: 414
Solved Threads: 163
Skill Endorsements: 10