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
Hitman42 [59]
4 years ago
12

Write code to complete raise_to_power(). Note: This example is for practicing recursion; a non-recursive function, or using the

built-in function math.pow(), would be more common. Sample output with inputs: 4 2 4^2 = 16
Engineering
2 answers:
Mamont248 [21]4 years ago
6 0

Answer:

See the explanation

Explanation:

Note that, given a base number b and and exponent e we have that b^e consists of multyplying b, e times. This means, to call the function e times of multiplying the result by b. Then consider the following code

int raise_to_power(int base, int exponent){

if exponent =0

then return 1

else

return base * raise_to_power(base,exponent-1)

}

Note that if base = 4 and exponent = 2

At first, we have that 2 is not 0, so it will multiply 4 times raise_to_power(4,1). But raise_to_power(4,1) will return 4 times raise_to_power(4,0). And raise_to_power(4,0)=1. So, the final result will be 4 * 4 * 1 = 16 which is de desired result.

Zina [86]4 years ago
4 0

Answer:

#include <stdio.h>

int RaiseToPower(int baseVal, int exponentVal){

int resultVal = 0;

if (exponentVal == 0) {

resultVal = 1;

}

else {

resultVal = baseVal * /* Your solution goes here */;

}

return resultVal;

}

int main(void) {

int userBase = 0;

int userExponent = 0;

userBase = 4;

userExponent = 2;

printf("%d^%d = %d\n", userBase, userExponent, RaiseToPower(userBase, userExponent));

return 0;

}

Explanation:

You might be interested in
A customer complains that the car pulls to the left during hard braking. An inspection shows that the front pads and rear shoes
dezoksy [38]
Technician B I did this in my lesson and the right answer is B
5 0
3 years ago
Q1: The first option should always be to get out safely (RUN)
nekit [7.7K]

Answer:

Q1 true

Q2 true

And other I am confuse

6 0
3 years ago
Why is Ethics an important part of engineering?
NemiM [27]

Answer:

Products created can change society, for better and for the worse

It was damaged in a fire

8 0
3 years ago
You have a motor that runs at 1.5 amps from a 12 volt power source, how many watts of power is it using?
Leviafan [203]

Answer:

18 Watts

Explanation:

For this problem, we simply need to understand the relationship of power to voltage and current.  This relationship is derived from Ohm's law:

Power = Voltage * Current

Given this equation, we can say the following to find the power consumption of the motor:

Power = 12volts * 1.5amps

Power = 18 Watts

Hence, the motor is consuming 18 Watts of power.

Cheers.

3 0
3 years ago
Giving free brainlist first 1
kaheart [24]

Hi! Hope you're having a great day!

8 0
3 years ago
Other questions:
  • Air at 80 kPa and 10°C enters an adiabatic diffuser steadily with a velocity of 150 m/s and leaves with a low velocity at a pre
    11·1 answer
  • An engineer is designing an irrigation system to bring water to a farm. Which
    12·2 answers
  • Air is flowing in an insulated duct at a rate of 2 kg/sec. Air enters the duct at 40 oC and 8-kW of heat is added with a electri
    5·1 answer
  • Given the strings s1 and s2, not necessarily of the same length, create a new string consisting of alternating characters of s1
    5·1 answer
  • An alloy has a yield strength of 41 ksi, a tensile strength of 57 ksi, and an elastic modulus of 16 * 106 psi. A cylindrical spe
    5·1 answer
  • Air at 105 kPa and 37° C flows upward through a6-cm-diameter inclined duct at a rate of 65 L/s. The duct diameter is then reduce
    12·1 answer
  • When you an angle you divide it into two equal part s
    13·2 answers
  • I have a Dutch oven that looks like this what do I do?
    10·1 answer
  • A skull and crossbones pictogram indicates this kind of information about a chemical.
    14·1 answer
  • There are some sections of the SDS that are not mandatory.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!