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

Search This Blog

#Day85#100DaysChallenge- Matlab Loops | Factor of a Number-2

#Day85-Factor of a Number-2

Task:

Write a code to Find factor of a Number
 Factor of 12-2,2,3


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

Matlab code

function fact=check_lcm(a)

inc=1;

 

while a>=2

if mod(a,2)==0

    fact(inc)=2;

    inc=inc+1;

    a=floor(a/2);

elseif mod(a,3)==0

     fact(inc)=3;

    inc=inc+1;

     a=floor(a/3);

elseif mod(a,5)==0

      fact(inc)=5;

    inc=inc+1;

     a=floor(a/5);

else

   

    fact(inc)=a;

   

     a=floor(a/a);

end

end

if a~=1

    fact(inc)=a;

end

Sample Input and Output


>> fact=check_lcm(300)


fact =


     2     2     3     5     5 

   

Click here for Video description





Live Support: t.me/matlabirawen


   

 


No comments

Popular Posts