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
Cindy tried to delete a customer but the customer still had open invoices so the system would not allow her to delete the custom
Verdich [7]

Answer:

The answer is "Referential integrity".

Explanation:

This relates to one aspect of data integrity. Data across multiple tables are linked via relationships. In view of the distinct customer & invoice tables, each invoice table should have the primary key specified throughout the Customer table, for instance. Whenever the invoice table contains a customer ID reference. This ID including its customer will be only a table of the customer.

8 0
3 years ago
A form of Internet identity theft involving phony e-mail messages asking customers to update their credit card numbers, account
irina [24]

Answer: Phishing

Explanation:

Phishing is a form of identity theft involving phony email messages asking customers to update credit, debit, cards, accounts passwords, and all whole of personal information. It is still one of the relevant form of identity theft whereby personal information is taken away in form of electronic communication or messages.

One example could be when a person receives a mail from xyz.com and ask him/her to click on a page. upon clicking on it the person will be redirected to another page. in that page several details would be there such as username and password, bank account details. So once all these details are entered in the web page all our personnel information will leaked into the servers of the hackers and could lead to serious troubles. Sometimes phishing is also in form of fake social networking website which resembles exactly to that of the original one.

So Phishing is a for of identity theft.

3 0
3 years ago
3.1.1 What type of goods are car radio and remote control.​
Nuetrik [128]

Answer:

Radio Controlled cars .

4 0
2 years ago
Terri needs to insert a cover page into her document. Where should she go to access the commands to do so? Insert tab, Objects g
dexar [7]

Answer:

Insert tab, Pages group

Explanation:

It just be like dat

7 0
2 years ago
Which organization developed a network called CSNET to provide a network free to all American research and educational instituti
Citrus2011 [14]
<span>The National Science Foundation (NSF) is the organization which </span><span>developed a network called CSNET to provide a network free to all American research and educational institutions. It is an agency in the government of the United States that is responsible for research and development in the field of science and engineering. </span>
7 0
3 years ago
Other questions:
  • Which of the following information security technology is used for avoiding browser-based hacking?
    11·2 answers
  • Read at least three (3) academically reviewed articles on Management Information Systems and complete the following activities:
    5·1 answer
  • A_____refers to the entire Excel file
    14·1 answer
  • What is a Limited Purpose credit card
    11·2 answers
  • 6. Write a program that can multiply an n x m matrix and m x n matrix together: The input specifications are these: Read n and m
    11·1 answer
  • What error occurs when you perform an illegal math operation such as divide by zero
    13·1 answer
  • You recently started working part-time in a retail store, and are learning about the reading devices your store uses. Your store
    10·1 answer
  • Compile and Execute a Program
    13·1 answer
  • Some applications required advanced storage solutions are available to provide fault tolerance and high performance.
    13·1 answer
  • FIRST TO Answer for free brainlest. GOG GOGOGO
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!