Performing the iteration procedure to repeat the process

We will start with the iteration process. As we discussed earlier, the calculation of a factorial will be better if it's designed using the recursion approach. However, it's possible as well to design it with the iteration approach. Here, we will have a factorial_iteration_do_while.cpp code that we can use to calculate the factorial. We will have a function named factorial () that passes a single parameter that will calculate the factorial value we pass in the argument. The code should look like this:

    /* factorial_iteration_do_while.cpp */    #include <iostream>    using namespace std;    // Function containing    // do-while loop iteration    int factorial (int n)    {      int result = 1;      int i = 1; // ...

Get Learning C++ Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.