After you determine what the program of Exercise 5.45 does, modify the program to func- tion properly after removing the restriction that the second argument be nonnegative.
What will be an ideal response?
```
// Multiply integers (positive or negative) using recursion.
#include
using namespace std;
int mystery( int, int ); // function prototype
int main()
{
int x; // first integer
int y; // second integer
cout << "Enter two integers: ";
cin >> x >> y;
cout << "The result is " << mystery( x, y ) << endl;
} // end main
// mystery multiplies a * b using recursion
int mystery( int a, int b )
{
if ( b < 0 ) // if b is negative
{
// multiply both a and b by -1, so b is positive
// note this multiplies answer by (-1)*(-1) = 1
a *= -1;
b *= -1;
} // end if
if ( b == 1 ) // base case
return a;
else // recursion step
return a + mystery( a, b - 1 );
} // end function mystery
```
You might also like to view...
When you click the Enter button to complete an entry in a cell, the active cell moves down to the next cell in the same column.
Answer the following statement true (T) or false (F)
Related tasks that further define summary tasks are called ________
Fill in the blank(s) with correct word
The control unit is one component of the ________.
A. CPU B. cache C. front side bus D. clock
A print server uses a print ________ as a software holding area for jobs waiting to be printed.
A. stack B. spooler C. logger D. heap