[Newbie] Factorial

This is a discussion on [Newbie] Factorial within the C Programming forums, part of the General Programming Boards category; Hi, I'm doing my homework and I'm stuck on this factorial part. I know this is the code for n! ...

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Aside from the fact that mfact(1) no longer works, and that your code formatting could be improved, it looks okay to me. You do not actually need another variable in main() though, since n can be reused.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

You should just write mfact() to compute the factorial of any integer >= 0. Then just plug in 2*n when you call it. You're not going to accomplish or simplify anything by trying to change the body of the function itself. BTW, if you replaced "if (m == 1)" with "if (m == 0)" you could have it handle the case 0! == 1.