Hello again people!, this post is about my new program “Factorial Calculator”, and as the name says, it calculates the factorial of the number that you choose. But what is a factorial?
The factorial function (symbol: !) means to multiply a series of descending natural numbers. Examples:
- 4! = 4 × 3 × 2 × 1 = 24
- 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040
- 1! = 1
(Information taken from https://www.mathsisfun.com/numbers/factorial.html).
Here is the code of the program:
As you can see, here we have to use the for loop, and that’s new for me, so we have some problems with it, but finally I learned how to use it and it’s so easy.
The for loop has the next sequence.
for ( the variable that are you going to use as a counter; the condition; and finally the variable with ++ to add 1 when the cycle is repeating)
{
The proccess of the loop
}
It seems like that.
for (int m=1; m<=num1; m++)
{
result=m*result;
}
So it was the new thing that i learned with this program, the for loop.
Now, check my program running:
If you have problems with it, you can see this information:
http://www.tutorialspoint.com/cprogramming/c_for_loop.htm
and if you dont understand clearly, dont feel affraid and ask me!
Here my code on GitHub, hope it will be useful for you!.
https://github.com/eduardomrlsg/TC101/blob/master/FactorialCalculator
Regards!
EdM
#WSQ09 Factorial Calculator. by eduardomoralesg is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.