# i need help with the matlab assigment i have done all the part but i just need to store them in vector and display the user output number and all its divisors in a meaningful

2 views (last 30 days)
Rebecca on 27 Sep 2022
Edited: Torsten on 27 Sep 2022
- Ask the user to input an integer number between 50 and 100.
- Check the user input. If the input is not an integer within the specified range,
display an error message and ask the user for another input. Iterate this process
until satisfactory input is obtained.
- Find all the divisors of the given number and store them in a vector.
- Display the user input number and all its divisors in a meaningful way.
Test your program with three user inputs: 49, 56, and 57.
Steven Lord on 27 Sep 2022
Since this is a homework assignment please show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Rebecca on 27 Sep 2022
sum = 0;
x = input ( 'please input an integer number between 50 and 100;');
while (rem(x,1)~=0) || (x<50)|| (x>100)
x = input('your input is not an integer between 50 and 100 please try again:');
end
if rem(x,50)==0
if rem(x,100)==0
disp('the number entered can be devided by both 50 and 100')
else
disp('the number entered can be divided by 50,but not 100')
end
elseif rem(x,100)==0
disp('the number entered can be divided by 100, but not 3')
else
disp('the number entered can not be divided by 3 or 5')
end

Steven Lord on 27 Sep 2022
sum = 0;
You should use a different name for this variable, as sum already has a meaning in MATLAB.
x = input ( 'please input an integer number between 50 and 100;');
while (rem(x,1)~=0) || (x<50)|| (x>100)
x = input('your input is not an integer between 50 and 100 please try again:');
end
So this satisfies the first two bullet points in your assignment pretty well. [You might want to check that the user entered only one number and not something like [75 91] at the prompt.] Next tackle the third bullet point:
- Find all the divisors of the given number and store them in a vector.
If I gave you a number, say 60, what process would you follow with pencil and paper to find all the divisors? Start writing the steps you'd follow as comments. Once you have your workflow documented, start implementing each step. If you're not sure how to perform one or more of the steps in MATLAB, search the documentation to see if there's a function that will perform that step for you and/or break the step down into smaller sub-steps that you know how to implement.
Walter Roberson on 27 Sep 2022
The question is what process you followed to determine that list of divisors?
Torsten on 27 Sep 2022
Edited: Torsten on 27 Sep 2022
Since the list of divisors to check is only 1 to 50 for numbers between 50 and 100, maybe the easiest way is brute-force: Check whether i divides the given number "for i=1:50".