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
What is the advantage of maintaining a list of keywords while creating a design blueprint?
elixir [45]

Creating a list of keywords and using them throughout your site helps move pages up the ranks of search engines like Bing or Google. They also attract website visitors. Technically, maintaining a list of keywords while creating a webpage is important in search engine optimization.






8 0
3 years ago
Read 2 more answers
(a)Ms word is a isa word processing software ,(b)hub provides physical connection between all computers, State true or false​
8090 [49]

Answer:

true

Explanation:

true in answer in the question

8 0
3 years ago
Read 2 more answers
Need help plz 100 POINTS
steposvetlana [31]

Answer:

salamat sa points wreker

7 0
2 years ago
Read 2 more answers
The color gradient is
Kipish [7]
A range of position dependent colors
8 0
3 years ago
Can you prove that the bleu areas are the same please?
Nookie1986 [14]

\huge\color{darkred}{ \tt{NO!!}}

8 0
2 years ago
Read 2 more answers
Other questions:
  • In Paint, which of the following are ways to use a picture that you have saved on your computer? (Select all that apply.)
    8·1 answer
  • How does this app work?
    11·2 answers
  • You are having problems on your Windows 7 computer and you pull up Device Manager to see if there are any alerts. Two of your de
    11·1 answer
  • The largest type of computer system with the most extensive storage capacity and the fastest processing speeds is a ________.
    7·1 answer
  • If you're unsure of what chart to use for a set of data, what feature does Excel include that will help you to decide?
    7·1 answer
  • Select what's true about Search Engine Companies. Check All That Apply The information contained in a search engine database is
    12·1 answer
  • Which of the following would be least effective?
    10·1 answer
  • What are the disadvantages of vector images when compared to bitmap images?
    14·1 answer
  • Which wireless standard runs on both the 2.4 and 5 GHz frequencies?
    11·1 answer
  • How does digital and hybrid computers differ in portability​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!