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
Hitman42 [59]
3 years ago
15

Recursive Power Function Write a function that uses recursion to raise a number to a power. The function should accept two argum

ents: the number to be raised and the exponent. Assume that the exponent is a nonnegative integer. Demonstrate the function in a program.
Computers and Technology
1 answer:
Firlakuza [10]3 years ago
4 0

Answer:

// here is code in c++.

#include <bits/stdc++.h>

using namespace std;

// recursive function to calculate power of number

int cal_pow( int b_num, int e_num )

{

  if ( e_num > 1 )

      return b_num * cal_pow( b_num, e_num - 1 );

  else

      return b_num;

}

int main()

{

   // variables to store inputs

  int b_num, e_num;

  cout <<"Enter the base (int): ";

  //read the base

  cin >> b_num;

  cout << "Enter the exponent (int): ";

  // read the exponent

  cin >> e_num;

// call the function and print the output.

  cout << b_num << " to the " << e_num << " power is: "

      << cal_pow( b_num, e_num ) << endl;

  return 0;

}

//

Explanation:

Read value of base and exponent from user. Call the function cal_pow() with parameter base and exponent. In this function, it will call itself and multiply base value while exponent becomes 1.When exponent becomes 1 then base value will be return by the recursive function. In the last recursive call it will give the base to power exponent

Output:

Enter the base (int): 3                                                                                                    

Enter the exponent (int): 5                                                                                                

3 to the 5 power is: 243

You might be interested in
In the ____ letter style, all components of the letter begin flush with the left margin.
Sedaia [141]
In the block <span>letter style, all components of the letter begin flush with the left margin.</span>
4 0
3 years ago
One of the most obvious initial changes in windows vista is the ____ interface
lana [24]
Answer choices are not provided, but I would go for "Aero."
8 0
3 years ago
Two types of business communications enhanced by desktop publishing are
Likurg_2 [28]
The correct option is D.
The two types of business communication that are enhanced by desktop publishing are internal and external communication. Internal communication refers to the information and ideas that are exchange within the organisation while external communication refers to information and ideas that are exchange between the organisation and the outside world.<span />
4 0
3 years ago
Read 2 more answers
13. A 2-sided coin has an equal likelihood of landing on each side. One side is called "heads" and the other is called "tails".
serious [3.7K]

Answer: c

Explanation:

only reasonable answer

7 0
3 years ago
Rachel is on her way to an interview for the position of a project manager. She is trying to prepare for this interview by analy
Fittoniya [83]

The answer would be A.


5 0
3 years ago
Other questions:
  • What are three methods of sustainable farming and describe each.
    9·1 answer
  • If you delete a view, account administrators can recover the view using the "trash can" function within how many days?
    7·2 answers
  • How do you make your graphics ADA accessible in BlueGriffon?
    12·2 answers
  • Which best describes the differences between a resume and a CV?
    13·2 answers
  • Which workplace trend are outsourcing and telecommuting are examples of? Please select the best answer from the choices provided
    13·2 answers
  • If you change the text to bold,you are changing the what?
    9·1 answer
  • Does anyone know how to connect a nintendo switch to a laptop?
    10·2 answers
  • Can you sue someone in brainly? How is this not relate to education?
    5·1 answer
  • Describe s computer network that you are familiar with ?
    8·1 answer
  • While some audio recording programs are expensive, there are more user friendly,
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!