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
1 次查看(过去 30 天)
显示 更早的评论
- 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 个评论
Steven Lord
2022-9-27
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.
回答(1 个)
Steven Lord
2022-9-27
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
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.
4 个评论
Walter Roberson
2022-9-27
The question is what process you followed to determine that list of divisors?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!