Factorial

Hi this is my

Factorial

To calculate the factorial I did two codes showing two different ways to do this WSQ. The first is with loops. That is easy, I needed to declare 2 integer variables (“n” and “x”) and 3 character variables (answer, yes and no). Then I putted into a do-while all my code asking for a number and do the factorial with a while loop.

Here is the code in my GitHub for this first way.

 

In the second code of this wsq is about recursion. This means that I did a function to calculate the factorial of a number and then, in my “main” I call that function to prints the answer.

I found this information about recursion. That helped me to understand the concept and also, there are some examples with factorial. http://www.danzig.us/cpp/recursion.html

And here is my code for this second way to do this WSQ. I hope this post will help you.

CC BY 4.0 Factorial by Gonzalo Mata is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.