Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an iterative version (using a loop instead of recursion) of the factorial

ID: 3639321 • Letter: W

Question

Write an iterative version (using a loop instead of recursion) of the factorial function show in this chapter. Demonstrate the use of the function in a program that prints the factorial of a number entered by the user

Here is what I have so far...
#include <iostream>
using namespace std;

// Function prototype
int factorial(int);


int main()
{
int number;

// Perform some simple tests first
for (int i = 1; i < 6; i++) {
cout << i << "! = " << factorial(i) << endl;
}
cout << endl;

// Then prompt the user for another value
cout << "Enter an integer value and I will display its factorial: ";
cin >> number;
cout << "The factorial of " << number << " is ";
cout << factorial(number) << endl;
}

Explanation / Answer

/* Iterative Version */ unsigned int iter_factorial(unsigned int n) { unsigned int f = 1; for(unsigned int i = 1; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote