First please write a MATLAB function that finds all the divi

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.

Solution

%% 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

 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)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site