Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

#Day51 #100DaysChallenge- Matlab Loops|Power of a number

#Day51-Power of a Number
Task:

Write a code to find power of a  number. 
power(13,2)
Sum of Digits:169

Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
Matlab code

function power_value=powerofanumber(base,n)
power_value=1;
while(n~=0)
    power_value=power_value*base;
    n=n-1;
end
end

Sample Input and Output

>> powerofanumber(11,2)

ans =

   121

>> powerofanumber(11,9)

ans =

   2.3579e+09

>> powerofanumber(2,8)

ans =

   256

>> powerofanumber(2,3)

ans =


     8 



Click Here for Video Description




No comments

Popular Posts