3.5k views
0 votes
Functions with loops. C++

Define the function OutputVal() that takes two integer parameters and outputs the product of all integers starting with the first and ending with the second parameter, followed by a newline. The function does not return any value.
Ex: If the input is 1 4, then the output is:
24
Note: Assume the first integer parameter is less than the second.
------------------------------
#include
using namespace std;

/* Your code goes here */

int main() {
int numberA;
int numberB;

cin >> numberA;
cin >> numberB;
OutputVal(numberA, numberB);

return 0;
}

1 Answer

4 votes

Answer:

Here's the pseudocode for the OutputVal function:

function OutputVal(numberA, numberB)

result = 1

for i = numberA to numberB do

result = result * i

end for

output result followed by a newline

end function

Step-by-step explanation:

This function initializes result to 1 and then multiplies it by every integer from numberA to numberB using a loop. Finally, it outputs the value of result followed by a newline.

User Delmy
by
7.6k points