1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
bearhunter [10]
3 years ago
10

"Write an iterative function iterPower(base, exp) that calculates the exponential baseexp by simply using successive multiplicat

ion. For example, iterPower(base, exp) should compute baseexp by multiplying base times itself exp times"
Computers and Technology
1 answer:
sp2606 [1]3 years ago
5 0

Answer:

I am writing the function using Python. Let me know if you want the program in some other programming language.            

def iterPower(base, exp):    

    baseexp = 1

    while exp > 0:

        baseexp = baseexp*base

        exp= exp - 1

    return baseexp

base = 3

exp = 2

print(iterPower(base, exp))

Explanation:

  • The function name is iterPower which takes two parameters base and exp. base variable here is the number which is being multiplied and this number is multiplied exponential times which is specified in exp variable.
  • baseexp is a variable that stores the result and then returns the result of successive multiplication.
  • while loop body keeps executing until the value of exp is greater than 0. So it will keep doing successive multiplication of the base, exp times until value of exp becomes 0.
  • The baseexp keeps storing the multiplication of the base and exp keeps decrements by 1 at each iteration until it becomes 0 which will break the loop and the result of successive multiplication stored in baseexp will be displayed in the output.
  • Here we gave the value of 3 to base and 2 to exp and then print(iterPower(base, exp)) statement calls the iterPower function which calculates the exponential of these given values.
  • Lets see how each iteration works:
  • 1st iteration

baseexp = 1

exp>0 True because exp=2 which is greater than 0

baseexp = baseexp*base

               = 1*3 = 3

So baseexp = 3

exp = exp - 1

      = 2 - 1 = 1    

exp = 1

  • 2nd iteration

baseexp = 3

exp>0 True because exp=1 which is greater than 0

baseexp = baseexp*base

               = 3*3 = 9

So baseexp = 9

exp = exp - 1

      = 1-1 = 0    

exp = 0

  • Here the loop will break now when it reaches third iteration because value of exp is 0 and the loop condition evaluates to false now.
  • return baseexp statement will return the value stored in baseexp which is 9
  • So the output of the above program is 9.
You might be interested in
When creating a multi-dimensional array dynamically in C/C++ the Memory Manager will go to great pains to make sure the array is
yuradex [85]

Answer:

Here the statement is false.  

Explanation:

In C/C++, we can define multidimensional arrays in simple words as an array of arrays. Data in multidimensional arrays are stored in tabular form (in row-major order).  

General form of declaring N-dimensional arrays:  

data_type  array_name[size1][size2]....[sizeN];  

data_type: Type of data to be stored in the array.  

          Here data_type is valid C/C++ data type

array_name: Name of the array

size1, size2,... ,sizeN: Sizes of the dimensions.

Foe example:

Two dimensional array:

int two_d[10][20];  

Three dimensional array:

int three_d[10][20][30];

8 0
3 years ago
What is an internal node?
Phantasy [73]
An internal node is a node which carries at least one child or in other words, an internal node is not a leaf node.
8 0
3 years ago
Blogs may refer to any kind of communication over the internet is true​
Sliva [168]

Answer:

Yes It's true but You forgot email

Explanation:

6 0
3 years ago
The core of ___________ is the implementation of intrusion detection systems and intrusion prevention systems at entry points to
cestrela7 [59]

Answer:

sorry I can't understand what is this is

3 0
2 years ago
25 POINTS!! NEED HELP ASAP!! Which of the following can be a problem for people with certain kinds of epilepsy?
olga_2 [115]
There is your answer:
Flashing images
5 0
2 years ago
Other questions:
  • Remember that the function "main" takes optional parameters, these being common:
    10·1 answer
  • What is a binary message
    12·2 answers
  • Why is brainly not working it say im logged out rn but im not i cant acces anything but this
    12·2 answers
  • When Clara accesses the programs and documents on her computer by way of icons, she is said to be employing
    15·1 answer
  • In which of the following situations will a macro make your work more efficient?
    9·1 answer
  • Which types of scenarios would the NETWORKDAYS function help calculate? Check all that apply.
    7·1 answer
  • The command-line interface tells a user that it's ready to receive commands by displaying a specific set of characters called a(
    12·1 answer
  • Why do meteorologists use data such as temperature, wind speed, and air
    9·1 answer
  • Una laptop agarra mas internet que una computadora de escritorio?
    11·1 answer
  • The three main objectives of information security are
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!