Who can give me a full answer of this question?

2 次查看(过去 30 天)
Write a program which repeatedly reads numbers until the user enters "done". Once "done" is entered, print out the Max and Min. Use an array to store all the numbers. Example of execution:
Enter a number: 4
Enter a number: 5
Enter a number: 9
Enter a number: done
Max = 9, Min = 4
  12 个评论
Stephen23
Stephen23 2017-5-22
编辑:Stephen23 2017-5-22
@Emma Swaggy: well, you made me laugh, which is a fine thing indeed.
Most of us here will not do other people's homework, but we are all happy to help you if you have specific questions about MATLAB, or are unsure how to approach solving a problem. In return you have to put in the effort yourself and show some initiative: for example MATLAB has very readable documentation which is easy to search using [your favorite internet search engine]. The documentation also includes working examples for almost every operation and function: the more you try yourself the more you will learn, the more you will understand, and the easier it will be for us to help you. We are not babysitters, nor a free tutor service, nor are we going to write all of your homework for you.
But please do ask us questions about how to use MATLAB.
You should start by doing the introductory tutorials (yes, really):

请先登录,再进行评论。

回答(2 个)

KSSV
KSSV 2017-5-22
For your work..you have to read about
1. input
2. min and max
3. disp
  3 个评论
KSSV
KSSV 2017-5-22
@ Emma Swaggy....this is what we want here..you try out and have a problem then pose the question,, people would be happy to help/ answer you.
Thomas Nguyen
Thomas Nguyen 2018-4-7
@EmmaSwaggy: next time you could search google :p it's really simple just find the keywords (For example here it's quite simple to spot out the keywords are min, max, input (like @KSSV said) ) then add "matlab" either the beginning or end :p

请先登录,再进行评论。


Thomas Nguyen
Thomas Nguyen 2018-4-8
Code:
function[] = someonesHW()
idx=1;
prompt='Enter a number: ';
while true
inp=input(prompt,'s');
if (inp=="done")
break;
else
a=str2double(inp);
if isempty(a)
disp('Invalid input!');
continue
elseif isnumeric(a)==1
A(idx)=a;
idx=idx+1;
end
end
end
Min=min(A(:));
Max=max(A(:));
disp(['Max = ',num2str(Max),'; Min = ',num2str(Min)]);
end%someonesHW()

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by