Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab Help There are m people sitting in a circle. We choose the tallest peopso

ID: 1716799 • Letter: M

Question

Matlab Help There are m people sitting in a circle. We choose the tallest peopson and label him No. 1. the next tallest is No. 2 and so on and so forth. then we start counting clockwise from No.1, and remove the n-th person from circle. the process continues until there is only one person left. Write a function to calculate the orginal No. of the last person. Write down you MATLAB function file using proper font and size. What is the result if the : 1). m=19 and n= 5 and 2). m=35 and n= 6? I need a list of commands on how to do this please help me!

Explanation / Answer

The algorithm for the above problem looks like this:

1) m people sitting in a circle can be stored in an array of m elements of different heights.

2) Arrange the array in a descending order of height.

3) Count the from the top of the array and remove the nth person.

The matlab code is given below:

clear
clc
m = input('number of persons =');
for i=1:m
fprintf('height of %g person = ', i);
a(i)= input('height = ');
end
for i=1:m-1
if (a(i) < a(i+1))
temp = a(i);
a(i)=a(i+1);
a(i+1) = temp;
end
end
n = input('number=');
for i=1:m
if (i==n)
for j=n:m-1
a(j)=a(i+1);
end
end
end

Above program could be run for any value of m and n but n should be less than or equal to m.