#Day51 #100DaysChallenge- Matlab Loops|Power of a number
#Day51-Power of a Number
Task:
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
Sample Input and Output
8
Click Here for Video Description
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
>> powerofanumber(11,2)
ans =
121
>> powerofanumber(11,9)
ans =
2.3579e+09
>> powerofanumber(2,8)
ans =
256
>> powerofanumber(2,3)
ans =
Click Here for Video Description
No comments