TASK: Determine and print the factors of an integer N, using WHILE.
COMMENT: We will assume N is greater than 1. Suppose "i" is a factor of "n". Then the MATLAB function mod(n,i) will have a value of 0. So i is a factor of n. But i might be a factor several times. So we need to divide n by i, and check again. If i is not a factor, then we need to check the next possible divisor, increasing i by 1.
INSTRUCTIONS:
Use MATLAB's input() statement to request an integer "n"
greater than 1;
Initialize your possible factor "i" to 2.
Every time we find a factor, we will divide it out of n. So our
process can stop once n reaches the value 1. In other words, we
want to keep going "WHILE n is not 1". Make this your outer loop.
Inside this loop, we know n is not down to 1 yet. Our current
possible divisor is i. I might be a factor, and it might be a
factor several times. So..."WHILE i is a factor of n" we want
to divide n by i, AND print out the value of i.
Once we can't divide evenly by i, then we want to increase i
by 1, and begin the outer loop again.
Here is an outline of your code:
get n
set i
repeat as long as n is greater than 1
if n is divisible by i
divide n by i
print i
end of loop
increase i
end of loop
CHECK:
n = 21:
3 7
n = 22
2 11
n = 23
23
n = 24:
2 2 2 3
n = 25
5 5
SUBMIT: Your work should be stored in a script file called "hw013.m". Your script file should begin with at least three comment lines:
% hw013.m
% YOUR NAME
% This script (describe what it does)
% Add any comments here that you care to make.
If this problem is part of an assignment, then submit it to Canvas.