First, please write a MATLAB function that finds all the divisors between 2 and
ID: 2314711 • Letter: F
Question
First, please write a MATLAB function that finds all the divisors between 2 and 20 of an integer. Your function header should be function div = finddivisor (a) where the input a is an integer, the output div is a vector that contains all of the divisors of a that are between 2 and 20. For example, if the input is 42, its divisors between 2 and 20 are 2,3,6, 7,12,14,18 (21 is also a divisor of 42, but larger than 20, so does not count here). The output should be div = [2 3 6 7 12 14 18]. Once you construct your MATLAB function find divisor. use it to find all the divisors (between 2 and 20) of your WSU student ID number.Explanation / Answer
%% MATLAB code to find divisors of given number
clear
clc
a=input('Enter Number = ')
i=1;
k=1;
for i=1:1:20
d=mod(a,i);
if (d==0&&i>1&&i<=20)
divisor(k) = i;
k=k+1;
end
end
Divisor = divisor
Output :
Enter Number = 42
a =
42
Divisor =
2 3 6 7 14
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.