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
USPshnik [31]
3 years ago
5

Complete the recursive function raisetopower(). ex: if userbase is 2 and userexponent is 4, then raisedvalue is assigned with 16

(i.e. 2^4). note: this example is for practicing recursion; a non-recursive function, or using the built-in function pow(), would be more common.
Computers and Technology
1 answer:
lesya [120]3 years ago
6 0
Using the property that x^n is x*x^(n-1) you can write a recursive function:

double raisetopower(double x, int n)
{
   if (n <= 0) {
      return 1.0;
   }
   return x*raisetopower(x, n - 1);
}

Note that this crude implementation does not deal with negative or fractional exponents. But it shows recursion.

You might be interested in
Write a loop that reads strings from standard input where the string is either "land", "air", or "water". The loop terminates wh
____ [38]

Answer:

count_land = count_air = count_water = 0

while True:

   s = input("Enter a string: ")

   if s == "xxxxx":

       break

   else:

       if s == "land":

           count_land += 1

       elif s == "air":

           count_air += 1

       elif s == "water":

           count_water += 1

print("land: " + str(count_land))

print("air: " + str(count_air))

print("water: " + str(count_water))

Explanation:

*The code is in Python

Initialize the variables

Create a while loop that iterates until a specific condition is met. Inside the loop, ask the user to enter the string. If it is "xxxxx", stop the loop. Otherwise, check if it is "land", "air", or "water". If it is one of the given strings, increment its counter by 1

When the loop is done, print the number of strings entered in the required format

4 0
2 years ago
Which type of exception would be detected if you used the conversion command Convert.ToDecimal to try to convert an ampersand?
Anestetic [448]

Answer:

Visual basic

Explanation:

Implicit and Explicit Conversion

4 0
2 years ago
Daniel was appointed one of three princes over all 120 governors in the kingdom of: Belshazzar, Darius, Nebuchadnezzar, Jerioaki
Dovator [93]
The correct answer is DARIUS.
It is written in the bible in Daniel chapter 6 verses one and two: ' It pleased Darius to set over the kingdom 120 satraps, to be over the whole kingdom. And over these, three governors of whom Daniel was one, that the satraps might give accounts to them, so that the king would suffer no loss. 
5 0
3 years ago
What are Loop Errors? Describe briefly. What aresymptoms of Loop Errors?
victus00 [196]

Answer:

The errors in the loop condition such that it is not giving desired results or it is not running accordingly.There are different types of loop errors which are as following:-

1.Infinite loop:-When the is not able to stop then the error is called infinite loop. for ex:-

int i=1;

while(i!=0)

{

cout<<"I am King"<<endl;

i++;

}

2.Off by one error:-This error mostly happens in loop for arrays as indexing of the array is from 0 to size-1 .So looping over the array up to the size is a off by one error.

3.Equality v/s assignment operator error:-In this error the condition in the loop is like this d=f which is wrong since = is assignment operator it assigns the value of f to d while d==f checks that the value of d and f are equal or not.

4.&& v/s || loop error:- In this error we use and operator (&&) instead of or operator (||) and vice versa.

symptoms of loop errors are not the desired output.

4 0
2 years ago
Why does an annular eclipse occur when the moon is between the sun and Earth, but is too far from Earth for a total eclipse?
velikii [3]

Answer:

Moon Is Far from Earth

Explanation:

The reason we can see the glowing outer edge of the Sun at the maximum point of an annular eclipse is that it happens while the Moon is near its farthest point from Earth, called apogee, when the Moon is smaller than the Sun when viewed from Earth.

5 0
3 years ago
Other questions:
  • Numeric data is stored in ___________ for direct processing.
    10·2 answers
  • Marisol manages the online advertising campaigns for a chain of toy stores with both a physical and an online presence. Which Go
    7·1 answer
  • Digital dashboards provide the decision makers with a quick overview of key performance indicators and other key operational sta
    13·1 answer
  • Are one of the greatest features of Photoshop that allow nondestructive editing of images.
    6·1 answer
  • 1. In your own words, describe the purpose of a for a loop.
    11·1 answer
  • Erik is the president and owner of Watch Out, a local website development company that helps clients create and build unique web
    15·1 answer
  • Exercise#3: Write a program that performs the following: Declare a two arrays called arrayA and arrayB that holds integer and th
    14·2 answers
  • Please choose the correct option please tell fast​
    9·1 answer
  • What does the word collaborative mean?
    13·2 answers
  • External hard drives typically connect to a computer via an external port (such as a usb or ____ port) or a wireless connection.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!