228k views
5 votes
Write the definition of a function powerTo which recieves two parameters, a double and an integer. If the second parameter is positive, the function returns the value of the first parameter raised to the power of the second. Otherwise, the function returns 0.

1 Answer

5 votes

Answer:

Following is the definition of the required function:

def powerTo( double first, int second);

if second > 0;

double result = pow(first,second);

return result;

else

return 0;

Step-by-step explanation:

The explanation for above code is as follows:

  • A function named powerTo is defined, having two arguments with data type double and integer respectively.
  • A if condition is applied that checks the second parameter.
  • If the the condition: second > 0 gets true, a value is returned which is equal to first parameter raised to the second.
  • If the condition is if bracket gets false, 0 is returned as a result.

i hope it will help you!

User Pkarfs
by
6.0k points