Question
Exponentiation and GCD WRITE A C++ PROGRAM Provide an iterative function named integerPower( base, exponent ) that returns the value of base exponent and an
Exponentiation and GCD
WRITE A C++ PROGRAM
Provide an iterative function named integerPower( base, exponent ) that returns the value of baseexponent and an iterative method named gcd( number1, number2 ) that returns the greatest common divisor of the numbers, number1 and number2. You may use Euclid's Algorithm to find the gcd.
Example result for GCD function: gcd(1543416,144) should return the value of 24.
For example: integerPower(3,4) calculates 34 ( or 3 * 3 * 3 * 3 ) = 81. Assume that the exponent parameter is a positive, nonzero integer; the base should be assumed to be any integer. Use a for loop or a while loop ( your choice ) as the control structure of the calculation.
If you want the extra challenge, look up the concept of exponentiation by squaring and try this method (1 point extra credit)!
Incorporate these functions into a program that prompts the user to enter a base, and exponent (for integerPower), also prompts the user for number1 and number2 (for gcd); then outputting the results.
Do not use the cmath library functions.
thanks alot for the help guys
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started