factorial

how can write a function that calculate int fact(int n) output should be n!
closed account (18hRX9L8)
Did you start? Post your code up here if you did and we will help you fix it.
Last edited on
i don't know how to write
closed account (18hRX9L8)
keskiverto wrote:
http://www.cplusplus.com/doc/tutorial/

For now, go through this tutorial to learn about how to program in C++. As you go through each lesson, you should complete exercises about that lesson so you can retain and try out the new information.

Note: You can't learn how to program this in a couple of weeks (or months), and if you are interested in learning more than the scope of this problem, it will take even years to get a full grasp of harder problems. Don't be discouraged though, learning how to program in C++ has many rewards.

Good luck,
Usandfriends
Last edited on
http://www.cplusplus.com/doc/tutorial/functions/

Go to the very bottom they actually have a factorial example using recursion.

You could also use a while loop if you didn't want to have as much on the stack.
Topic archived. No new replies allowed.