reads in n numbers from the user,storing the numbers in a vector, then print the numbers from the ends inwards(la​st,first,s​econd last,second)

2 次查看(过去 30 天)
% question demo
% How many numbers will you enter? : 5
% Enter a number: 3
% Enter a number: 5
% Enter a number: 6
% Enter a number: 4
% Enter a number: 3
% Your numbers from outside to middle are : 3 3 4 5 6
% I have no ideo how to do that
  1 个评论
Rik
Rik 2022-8-19
@Cheryl Pope:
I'm not a lawyer, but this doesn't look to me like it rises to the level of creatitivity that is required for copyright. This is an algorithm description with a tiny example. While copying an answer without attribution likely constitutes some for of academic fraud, I don't see how you would have grounds to have this deleted.
It is of course possible the OP agreed to some condition as part of the course to not share the question. In that case, you have a case against the OP.

请先登录,再进行评论。

采纳的回答

Arif Hoq
Arif Hoq 2022-3-20
try this:
numbers = input('How many numbers will you enter: ');
% create a empty vector to store the numbers
n = [];
Opsetnumber=cell(length(numbers),1);
% use nested loop
for i = 1:numbers
Numbers = input('Please enter a number: ');
n= [n,Numbers]; % let variable n to store the entered number from users
Opsetnumber = [];
for j = n:-1:1
Opsetnumber{i} = n;
end
end
output=sort([Opsetnumber{:}])';
% fprintf('Your numbers form outside to middle are: %d\n',output);
vec = ['Your numbers form outside to middle are: [', repmat('%g, ', 1, numel(output)-1), '%g]\n'];
fprintf(vec, output)
  15 个评论
Rik
Rik 2022-3-28
Why are you dynamically growing the array? And why the cell array? Also, your order is hard-coding the number of elements.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by