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
In the word interrupting, the root word rupt means:
Tatiana [17]
A. break, because if you were to interrupt someone mid-conversation you would essentially be 'breaking' their speech. In erupt it seems more like burst but could also be break because the lava erupting from the volcano breaks or damages its surroundings. Just a guess.
5 0
4 years ago
Read 2 more answers
You bought a laptop assuming it had application software loaded so you could use it right away, but it did not. What quality con
docker41 [41]

The quality consideration that this laptop did not meet is: fitness for use.

<h3>What is a laptop?</h3>

A laptop can be defined as a small, portable computer that is embedded with a keyboard and mousepad, and it is usually light enough to be placed on an end user's lap while he or she is working.

In this scenario, the laptop you purchased didn't have preinstalled software applications that you could use right away. Thus, we can conclude that the laptop is not <u>fit for use</u> because it didn't meet the quality consideration.

Read more on a laptop here: brainly.com/question/26021194

6 0
2 years ago
1. [10 marks] We begin with some mathematics regarding uncountability. Let N = {0, 1, 2, 3, . . .} denote the set of natural num
crimeas [40]

Answer:

Please see attachment

Explanation:

Please see attachment

Download pdf
6 0
4 years ago
Write a program to read 2 numbers and display the largest of the two. You should use scanfto read the two numbers and use if sta
Harman [31]

Answer: in C

#include <stdio.h>

int main(){

  int num1, num2;

  printf("Enter first number :: ");

  scanf("%d", &num1);

  printf("Enter second number :: ");

  scanf("%d", &num2);

 

  if(num1 > num2){

     printf("%d is larger than %d\n", num1, num2);

  } else if (num2 > num1) {

     printf("%d is larger than %d\n", num2, num1);

  } else{

     printf("Both of them are equal\n");

  }

  return 0;

}

8 0
4 years ago
Which column and row references are updated when you copy the formula f$3/15
Tasya [4]

Answer: Column F

Explanation: In Microsoft excel, for the sake of robustness and to aid the effectiveness of updating formulas across cells. The reference of cells are treated as relative which means that when formulas are copied across columns or within rows, they get updated automatically. However, some numbers may be treated as constants such that we do not want them to change or be updated as we move acisss cells. Thus, such numbers are treated Given absolute references, which is made possible by adding a '$' prefix before the colum alphabet or row number or both. in the scenario given above, the row has the $ prefix, hence, it is absolute and will not change but the column alphabet does not and hence, treated as relative.

3 0
3 years ago
Other questions:
  • Qual foi o primeiro computador no mundo a ser criado e qual é a hitória por trás?
    8·1 answer
  • The process of providing and denying access to objects is called:
    5·1 answer
  • Which is most likely a presentation file?
    8·1 answer
  • Can you find the ip address from a physical address
    13·1 answer
  • Tom's Art Supplies used to sell art supplies through mail order catalogs, but the company's order takers often had difficulty de
    9·1 answer
  • 1. Some of the music in the 1960s was used to protest social and political issues. Is music still used as a form of protest? Why
    13·1 answer
  • The suffix of a web address denotes which type of organization it is affiliated with. For example, an .edu is what type of websi
    9·1 answer
  • What type of data uses numbers that can be used in the arithmetic operations?
    14·1 answer
  • Why concurrency control is needed in transaction.
    5·1 answer
  • Hello everyone. New ppl on Ro.blox? I want to play sometime.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!