#Day84#100DaysChallenge- Matlab Loops | Factor of a Number
#Day84-Factor of a Number
Task:
Write a code to Find factor of a Number
Factor of 12-1 2 3 4 6 12
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
Matlab code
function factor_out=factor_ofnumber(a)
count=1;
for i=1:1:a
if mod(a,i)==0
factor_out(count)=i;
count=count+1;
end
end
end
>> factor_out=factor_ofnumber(60)
factor_out =
1 2 3 4 5 6 10 12 15 20 30 60
>> factor_out=factor_ofnumber(12)
factor_out =
1 2 3 4 6 12
>> factor_out=factor_ofnumber(36)
factor_out =
1 2 3 4 6 9 12 18 36
>> factor_out=factor_ofnumber(7)
factor_out =
1 7
Free Codes: youtube.com/castorclasses
No comments