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)

11 views (last 30 days)
% 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 Comment
Rik on 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.

Sign in to comment.

Accepted Answer

Arif Hoq
Arif Hoq on 20 Mar 2022
try this:
numbers = input('How many numbers will you enter: ');
% create a empty vector to store the numbers
n = [];
% 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;
% 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)
Rik on 28 Mar 2022
Why are you dynamically growing the array? And why the cell array? Also, your order is hard-coding the number of elements.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!