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 Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by