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 Ansichten (letzte 30 Tage)
% 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 Kommentar
Rik
Rik am 19 Aug. 2022
@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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Arif Hoq
Arif Hoq am 20 Mär. 2022
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 Kommentare
Rik
Rik am 28 Mär. 2022
Why are you dynamically growing the array? And why the cell array? Also, your order is hard-coding the number of elements.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by