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
AleksandrR [38]
3 years ago
8

Write a function named power that accepts two parameters containing integer values (x and n, in that order) and recursively calc

ulates and returns the value of x to the nth power.
Computers and Technology
1 answer:
lianna [129]3 years ago
8 0

Answer:

Following are the code to the given question:

int power(int x, int n)//defining a method power that accepts two integer parameters

{

if (n == 0)//defining if block to check n equal to 0

{

return 1; //return value 1

}

else//defining else block

{

x = x * power(x, --n); //use x variable to call method recursively

}

return x; //return x value

}

Explanation:

In the above-given code, a method power is defined that accepts two integer variable in its parameter, in the method a conditional statement is used which can be defined as follows:

  • In the if block, it checks "n" value, which is equal to 0. if the condition is true it will return value 1.
  • In the else block, an integer variable x is defined that calls the method recursively and return x value.
You might be interested in
Karel coding 2.1.4 superkarel cleanup
kherson [118]

Answer:

hi, try using Code Plans

Explanation:

it is a free website that include videos and articles on this stuff

6 0
3 years ago
Read 2 more answers
A chief Information Security Officer (CISO) is performing a BIA for the organization in case of a natural disaster. Which of the
nataly862011 [7]

Answer:

The correct answer is option (D) Identify the impact on safety of the property

Explanation:

Solution

In every Business Impact Analysis, the first and the most important step is for the CISO is to identify and estimate the impact of the aftereffects on the business and property of an organization that may be occurred from the disaster.

Physical security is very important, but it is not noticed by most organizations. It is important if you do not want anyone to take  away your information or destroy it, in case of natural calamity. the reason could be that, the intruder is  doing it for his personal achievement, financial gain,or seeking revenge or when one is taken unaware and becomes a target. If this security is not maintained properly all the safety measures will not be useful once the attacker gets through by gaining physical access.

Example of property can be software, equipment, facilities, company’s assets.

4 0
3 years ago
What is 1 TB equal to ?<br> . 1024 kb<br> .1024 gb <br>. 1024 pb <br>. 1024 mb​
OLEGan [10]

\large \mathfrak{Answer : }

1 TB = 1024 GB

3 0
3 years ago
Read 2 more answers
Session Hijacking refers to the exploitation of a valid computer session where an attacker takes over a session between two comp
noname [10]

Answer:Weak session ID generation algorithm

Explanation: Session hijacking is the hacking by disguising as the authenticated user and illegally exploit the particular computer session. IP packets are invoked by the disguised attacker into the active session between the legal computer user. It is also called session key.

It gives the hacker to use the data and services of the computer in an unauthorized manner. It arises due to the session of communication are not secure and strong,key used for session is weak etc.

5 0
3 years ago
Greedy Algorithm Design
Alik [6]

Answer:

The algorithm is as follows:

1. Start

2. Get the number of items (n)

3. Get the current price of the n items (a1, a2..... an)

4. Get the possible hiked price of the n items (b1, b2..... bn)

5. Calculate the difference between the current and hiked prices for each item i.e. d_i = b_i - a_i

6. Sort the differences in descending order (i.e. from the greatest to the least)

7. Buy items in this order of difference

8. Stop

Explanation:

The algorithm is self-explanatory; however, what it does is that:

It takes a list of the current price of items (say list a)

E.g: a = [100, 150, 160]

Then take a list of the hiked price of the items (say list b)

E.g: b = [110, 180, 165]

Next, it calculates the difference (d) between corresponding prices d_i = b_i - a_i

d = [(110 - 100),(180-150),(165-160)]

d = [10,30,5]

Sort the difference from greatest to lowest (as the difference is sorted, lists a and b are also sorted)

d = [30,10,5]

a = [150, 100, 160]

b = [180, 110, 165]

If there is no hike up to item k, the couple would have saved (i = 1 to d[k-1])

Assume k = 3

The couple would have saved for 2 item

Savings = d[1] + d[2]

Savings = 30 +10

Savings = 40

The saved amount will then be added to the kth item in list a i.e. a[k](in this case k = 3) in order to buy b[k]

Using the assumed value of k

a[k] = a[3]

a[3] = 160

b[3] = 165

Add the saved amount (40) to a[3]

New\ Amount = 40 + 160

New\ Amount = 200

This new amount can then be used to buy b[3] i.e. 165, then they save the change for subsequent items

8 0
3 years ago
Other questions:
  • A line of text that has an equal number of characters on either side of the horizontal center of the page is called____.
    14·1 answer
  • Criminal Investigation people called my house on an automated voice is this a scam ??
    13·1 answer
  • The type of operating system best suited to controlling a massive multiplayer online game is _____.
    15·1 answer
  • You want to find information about Paris, France in the last five years, written in English. What is the best way to search for
    5·2 answers
  • You have noticed that one of your DNS servers has possibly been compromised. You believe that a cached DNS entry for your domain
    8·1 answer
  • Which Numpy function do you use to create an array? (Points : 1) np
    5·1 answer
  • Declare a typedef struct named jumper_t that will have four parts: character array name that is 16 in length, double array of tr
    12·1 answer
  • Explain set associative mapping<br>​
    10·1 answer
  • So I tried asking for help with my code on stackoverflow but the people there were very condescending and mean plus my questions
    7·1 answer
  • A penetration testing service hired by the company has reported that a backdoor was identified on the network. What action shoul
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!