Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a function called FindPower that takes 2 scalars, base and exponent, and produces a scalar called result. The function finds the value of the
Write a function called FindPower that takes 2 scalars, base and exponent, and produces a scalar called result. The function finds the value of the base raised to the power of the exponent. Inputs: - base (numeric scalar): the base value of the power calculation - exponent (numeric scalar): the exponent value of the power calculation Outputs: - result (numeric scalar): the value of base raised to the power of exponent The output argument result is a (numeric) scalar. Hint: use a for loop to multiply the base value by itself exponent times. For example: For the given inputs: base =2; exponent =5 On calling FindPower: result = FindPower(base, exponent); produces result =32 In result the value of base raised to the power of exponent is shown. Complete the function FindPower to produce a scalar called nearestSquare. nearestSquare is the square of the integer that is closest to the result value. Inputs: - base (numeric scalar): the base value of the power calculation - exponent (numeric scalar): the exponent value of the power calculation Outputs: - result (numeric scalar): the value of base raised to the power of exponent - nearestsquare (numeric scalar): the square of the integer that is closest to result Hint: use a while loop to go through the outMultiples array and check if the sum of the digits is odd using the sum() and mod() functions. For example: For the given inputs: base =2; exponent =5 ouput nearestSquare =25 The function FindPower takes in a base of 2 and an exponent of 5 , and produces a result of 32 ( 2 raised to the power of 5). It then finds the nearestsquare of the integer that is closest to result, which is 25 (5 raised to the power of 5 ). NOTE that 36 (6 raised to the power of 6 ) is closer to 32 rather than 25 . That being said, we are looking for the nearest sqaure value that is eaither equal to the P1 result or is less than P 1. 12345function[result,nearestSquare]=FindPower(base,exponent)%Codeforresult%Nameend Code to call your function? Assessment
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started