(Exponentiation) Write a function integerPower(base, exponent) that returns the value of base exponent For example, integerPower(3, 4) = 3 * 3 * 3 * 3. Assume that exponent is a positive, nonzero integer and that base is an integer. Do not use any math library functions.

What will be an ideal response?


// Calculate exponentiation of integers.
#include
using namespace std;

int integerPower( int, int ); // function prototype

int main()
{
int exp; // integer exponent
int base; // integer base

cout << "Enter base and exponent: ";
cin >> base >> exp;
cout << base << " to the power " << exp << " is: "
<< integerPower( base, exp ) << endl;
} // end main
// integerPower calculates and returns b raised to the e power
int integerPower( int b, int e )
{
int product = 1; // resulting product

// multiply product times b e number of times
for ( int i = 1; i <= e; i++ )
product *= b;

return product; // return resulting product
} // end function integerPower

Computer Science & Information Technology

You might also like to view...

Write a shell script that copies the file named by its first argument to a file with the same name with the filename extension of .bak. Thus, if you call the script with the argument first (and a file named first exists in the work- ing directory), after the script runs you would have two files: first and first.bak. Demonstrate that the script works properly.

What will be an ideal response?

Computer Science & Information Technology

Which of the following typically refers to a software or hardware interface that enables two different types of networked systems or software to communicate?

A. switch B. router C. gateway D. brouter

Computer Science & Information Technology

A button that turns a feature on and off is called a ________ button

A) toggle B) dialog C) binary D) choice

Computer Science & Information Technology

In a shared workbook, information that is maintained about changes made in past editing sessions is called the:

A) review history. B) change history. C) save history. D) track history.

Computer Science & Information Technology