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

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();