This C++ program defines a function called factorial that takes an integer parameter n and returns the factorial of n. It initializes a variable fact to 1 and uses a for loop to multiply fact by each integer from 1 to n, storing the resulting product back in fact. The program returns the final value of fact, which will be the factorial of the original integer n passed to the function.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
26 views1 page
Lab 2 Question 3
This C++ program defines a function called factorial that takes an integer parameter n and returns the factorial of n. It initializes a variable fact to 1 and uses a for loop to multiply fact by each integer from 1 to n, storing the resulting product back in fact. The program returns the final value of fact, which will be the factorial of the original integer n passed to the function.