function factors = find_factors(n)
% FIND_FACTORS returns all factors of the input number n.
% 寻找一个数的全部因数
% Usage: factors = find_factors(n)
% Example: find_factors(6) returns [1, 2, 3, 6]
% Initialize an empty array to store the factors
factors = [];
% Loop through numbers from 1 to n
for i = 1:n
% Check if i is a factor of n
if mod(n, i) == 0
% If yes, append i to the factors array
factors = [factors, i];%就是利用新的方式定义数组
end
end
% Display the factors (optional, for debugging)
disp(factors);
end