# 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

9 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.
##### 2 CommentsShowHide 1 older comment
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.
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".

### Categories

Find more on Chebyshev in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by