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
zhuklara [117]
3 years ago
7

Given non-negative integers x and n, x taken to the nth power can be defined as: x to the 0th power is 1 x to the nth power can

be obtained by multiplying x to the n-1'th power with x Write a long-valued function named power that accepts two int parameters x and n (in that order) and recursively calculates and returns the value of x taken to the n'th power.
Computers and Technology
1 answer:
saveliy_v [14]3 years ago
4 0

Answer:

The power function can be written as a recursive function (using Java) as follows:

  1. static int power(int x, int n)
  2. {
  3.        if(n == 0){
  4.            return 1;
  5.        }
  6.        else {
  7.            return power(x, n-1 ) * x;
  8.        }
  9. }

Explanation:

A recursive function is a function that call itself during run time.

Based on the question, we know x to the 0th power is 1. Hence, we can just create a condition if n = 0, return 1 (Line 3 - 5).

Next, we  implement the logic "x to the nth power can be obtained by multiplying x to the n-1'th power with x " from the question with the code:  return power(x, n-1 ) * x in the else block. (Line 6 -8)

In Line 7, power() function will call itself recursively by passing x and n-1 as arguments. Please note the value of n will be reduced by one for every round of recursive call. This recursive call will stop when n = 0.

Just imagine if we call the function as follows:

int result =  power(2,  3);

What happen  will be as follows:

  • run Line 7 -> return power(2, 2) * 2    
  • run Line 7 -> return power(2, 1) * 2
  • run Line 7 -> return power(1, 0) * 2
  • run Line 4 -> return 1    (Recursive call stop here)

Next, the return value from the inner most recursive call will be return to the previous call stack:

  • power(1, 0) * 2   ->   1 * 2
  • power(2, 1) * 2   ->   1 * 2 * 2
  • power(2, 2) * 2   ->   1 * 2 * 2 * 2 - > 8 (final output)  
You might be interested in
5
Vilka [71]
Is there like a graph or something I can look at because then I can help you
5 0
3 years ago
Elaboren un texto acerca de una caracteristica o<br>componente de algun sistema tecnologico.<br>​
LUCKY_DIMON [66]

Answer:

<em>Teniendo en cuenta el sistema hidráulico se puede mencionar la siguiente característica teniendo en cuenta el principio de Pascal:</em>

  • <u><em>La presión ejercida sobre un fluido en área pequeña es igual a las fuerza ejercida sobre un fluido en un área más grande.</em></u>

Explanation:

<em>El principio de Pascal menciona en términos generales que l</em><u><em>a fuerza ejercida sobre un fluido se ejerce sobre el total del fluido y en todas las direcciones</em></u><em>, sin embargo, basado en este concepto se encuentra el principio de la prensa hidráulica (que se menciona en la respuesta), el cual se podría expresar de la siguiente forma:</em>

  • <em>F1/A1 = F2/A2</em>

<em>Donde:</em>

  • <em>F </em><em>= Fuerza ejercida.</em>
  • <em>A</em><em> = Área en la cual se ejerce la fuerza.</em>

<em>Lo que se busca es ejercer una fuerza en un área pequeña que se vea reflejado como una gran fuerza en un área más grande. Éste principio se suele usar para el levantamiento de maquinaria como automóviles en los concesionarios.</em>

8 0
3 years ago
Suppose two computers (A &amp; B) are directly connected through Ethernet cable. A is sending data to B, Sketch the waveform pro
ICE Princess25 [194]

Answer:

Physical / Data link layer

Explanation:

If two computers (A & B) are directly connected through Ethernet cable. A is sending data to B, the data would be transmitted if the network is clear but if the network is not clear, the transmission would wait until the network is clear.

The Open Systems Interconnection model (OSI model) has seven layers each with its own function.

The physical layer is the first layer responsible for data transmission over a physical link. The data packets are converted to signals over a transmission media like ethernet cable.

The data link layer is the second layer in the OSI layer responsible for transmission of data packets between nodes in a network. It also provides a way of detecting errors and correcting this errors produced as a result of data transmission.

4 0
4 years ago
Given : an int variable k, an int array currentMembers that has been declared and initialized, an int variable nMembers that con
atroni [7]

Answer:

The following are the code in the Java Programming Language.

//set the for loop

for (k = 0; k < nMembers; k++)

{

//check that currentMembers[k] is equal to the memberID

if (currentMembers[k] == memberID)

{

//then, initialize isAMember to true

isAMember = true;

//and initialize the value of nMembers in k

k = nMembers;

}

//otherwise

else

{

//initialize isAMember to false

isAMember = false;

}

}

Explanation:

<u>The following are the description of the program</u>.

  • Set the for loop statement that iterates from 0 and stops at the variable 'nMembers'.
  • Set the if conditional statement that checks the variable 'currentMembers[k]' is equal to the variable 'memberID' then, initialize 'true' boolean value in the variable 'isAMember' and also initialize the value of the variable 'nMembers' in the variable 'k'.
  • Otherwise, initialize 'false' boolean value in the variable 'isAMember'.
6 0
3 years ago
This algorithm works by selecting the smallest unsorted item in the list and then swapping it with the item in the next position
Juliette [100K]

Answer:

a) Bubble sort

Explanation:

Bubble sort is a type of sorting algorithm that swaps small value with a bigger value over a number of rounds called pass.

5 0
3 years ago
Other questions:
  • A slideshow that accompanies an oral report is known as what?
    6·1 answer
  • Which of these consoles have 64 bit architecture
    13·1 answer
  • Write a program that will read the weight of a package of breakfast cereal in ounces and output the weight in metric tons as wel
    15·1 answer
  • Which of the following skills do employers in any field expect their employees<br> to have?
    5·1 answer
  • This type of connector is the most common for connecting peripherals (printers, monitors, storage devices, etc.) to a windows co
    10·1 answer
  • Discuss the following
    14·1 answer
  • Conduct research to determine the best network design to ensure security of internal access while retaining public website avail
    9·1 answer
  • PYTHON:
    11·1 answer
  • Ergonomics implications of computer​
    12·1 answer
  • Using computers can lead to a number of physical safety issues. State and explain TWO(2) of these types of issues.​​​​​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!