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)

16 visualizaciones (últimos 30 días)
% 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 comentario
Rik
Rik el 19 de Ag. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by