#WSQ09 Factorial

In this task, we needed to create a program that ask the user for any nonnegative number to calculate its factorial and print the result on the screen. To do it, I used the for loop, a repetition control structure, which made things easier. Here is the program:

Code

The for loop has the following sintax:

for (init; condition; increment){

statements

}

In init, you can declare and initialize any loop control variables; in condition, the condition is evaluated and, if it is true, the body of the loop is executed, if false, it will stop; and, in increment, you can update any loop control variables.

Here’s the program being executed:

Code executed

To do this activiy, I consulted this web page: http://www.tutorialspoint.com/cplusplus/cpp_for_loop.htm

You can look at my code in my GitHub as well: https://github.com/alanvaldo/my-tc1017-stuff/blob/master/wsq9.cpp

CC BY 4.0 #WSQ09 Factorial by Alan Valdovinos is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.