finding the divisors for a number displaying the divisors between two numbers.

1 view (last 30 days)
I am trying to find the divisors of a number say 84 and I need to show the divisors from 2 to 20 so if the divisors are div=[1 2 3 6 7 14 21 42 84] how can I show the selected numbers between the numbers 2 and 20 (2</= div >/=20) so I get an answer of div=[1 2 3 6 7 14]
so far I have and I know this isnt right
%function div = finddivisor(a)
divisors(84)
disp(a>1)
disp(a<21)
this gets me close to my answer but i dont know how to get it into a form that shows the divisors alone

Accepted Answer

Stephen23
Stephen23 on 2 May 2016
Edited: Stephen23 on 2 May 2016
See this question:
>> N = 84;
>> V = 2:20;
>> D = V(rem(N,V)==0)
D =
2 3 4 6 7 12 14

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!