Clear Filters
Clear Filters

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

3 views (last 30 days)
factor cannot be the number we are testing
  1 Comment
Evan Charlesworth
Evan Charlesworth on 11 Nov 2018
Edited: madhan ravi on 11 Nov 2018
I've gotten this so far, but don't know where to go from here.
largestfactor=n-1;
while largestfactor>0
if mod(n,largestfactor)==0

Sign in to comment.

Accepted Answer

Bruno Luong
Bruno Luong on 11 Nov 2018
largestfactor=floor(n/2);
while largestfactor>0
if mod(n,largestfactor)==0
break
end
largestfactor = largestfactor-1;
end

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!