MATLAB: How to find the largest factor of a number using while loops

factorhomeworkwhile loop

factor cannot be the number we are testing

Best Answer

largestfactor=floor(n/2);
while largestfactor>0
if mod(n,largestfactor)==0
break
end
largestfactor = largestfactor-1;
end
Related Question